This can return true for all the check Palindrome. I need help here. function palindrome(str) {
return str === str.split(/^a-z0-9/gi).reverse().join("");
return true;
}
console.log(palindrome(“eye”));
This can return true for all the check Palindrome. I need help here. function palindrome(str) {
return str === str.split(/^a-z0-9/gi).reverse().join("");
return true;
}
console.log(palindrome(“eye”));
two things:
you are trying to compare str
with str
stripped of unwanted characters and then reversed - it will never be true even if it is a palindrome as the left hand side of the comparison has the unwanted characters
second, your regex doesn’t do what you want
this means "starts with a, then there is a dash then z then 0 then a dash then 9
if you want to say “is not a-z0-9
” you need to use a character class, so with the square brackets - to consider when there is more than one unwanted character you may also want to add the +
counter to say “split on one or more characters that are not a-z0-9”
Thanks for the clarification. I will camp on it again