-
Notifications
You must be signed in to change notification settings - Fork 0
Check for Palindromes
Islam Ibakaev edited this page Apr 27, 2016
·
3 revisions
Return true
if the given string is a palindrome. Otherwise, return false
.
A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.
Note You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.
We'll pass strings with varying formats, such as "racecar"
, "RaceCar"
, and "race CAR"
among others.
function palindrome(str) {
str = str.toLowerCase().replace(/[^a-z0-9]/g, '');
return str === str.split('').reverse().join('');
}
palindrome("0_0 (: /-\ :) 0-0"); // returns true