I'm trying to get this palindrome generator to work, and I cannot figure out how to get js to remove the white space from between the words in multi-word palindromes. race car keeps coming back false. racecar comes back true, so part of the code is working. How do I get JS to ignore the white space between "race" and "car" so that race car comes back as true?
function palindrome(word) {
var len = word.length;
word = word.replace(/ +/g, "");
for (var i = 0; i < Math.floor(len/2); i++ ) {
if (word[i] !== word[len - 1 - i]) {
return "FALSE";
}
}
return "TRUE";
}
console.log(palindrome("race car"))