Check for Palindromes why my code don't work if it should? [Spoiler]

Hi! after browsing forum i found what i have to change, and Icame with solution:
function palindrome(str) {
str = str.replace(/\W+/g, “”).replace(/_/g, “”).toLowerCase();
var str1 = str.split("").reverse().join("");
if (str == str1){
return true;
return false;

BUT I don’t know why if i make: str = str.replace(/[0-9]/g,"").replace(/\W+/g, “”).replace(/_/g, “”).toLowerCase(); code dosen’t work, becouse with “1 eye for of 1 eye.” I’m geting true, not false. From what i understood i first it replace all numbers, then characters and then _ and after it make it all lower case. Why it isn’t working, if only it’s just longer?

You shouldn’t be replacing 0-9, only non-alphanumeric characters.

1 Like

OMG :smiley: I’m so stupid :smiley: thanks! I should be more attentive :slight_smile:

No worries, we all get code-blindness from time to time :slight_smile: