I’ve been trying to write a palindrome function for the following algorithm challenge: https://www.freecodecamp.org/challenges/check-for-palindromes
Can anybody tell me why the code below isn’t returning any ‘false’ statements?
Thank you in advance.
function palindrome(str) {
strInLowerCase = str.toLowerCase();
readForward = strInLowerCase.replace(/[^a-z 0-9]+$/g);
readBackward = readForward.split().reverse().join("");
if (readBackward == readForward) {
return true;
}
return false;
}
palindrome(“not a palindrome”);