Tell us what’s happening:
Got most of the way through the Palindrome challenge but my code fails on the two with a period in them. I’m not sure why this is since I believe my regex should remove all non alphanumerics.
Your code so far
function palindrome(str) {
// Good luck!
var forwardStr = str.replace(/[\W_]/g, ''); // Removes all non-alphanumeric characters
forwardStr.toLowerCase(); // Changes all characters to lowercase
var tempArr = forwardStr.split(''); // Splits the modified string into an array of individual characters
tempArr.reverse(); // Reverses the array
var backwardStr = tempArr.join(''); // Joins the reversed array back into a whole string
if (forwardStr === backwardStr) {
return true;
} else {
return false;
}
}
palindrome("eye");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
.
Link to the challenge: