Check for Palindromes (palindrome("1 eye for of 1 eye."))

Tell us what’s happening:
only this test fails and for what I see this string should be a palindrome but the challenge say it should not,… any insight about this?

JIC: “eyeforofeye” that’s the word after implement the regex.

Your code so far

function palindrome(str) {
  // Good luck!  
  return str.toLowerCase().replace(/[^a-z]/g, "").split("").reverse().join("") == str.toLowerCase().replace(/[^a-z]/g, "");

palindrome("1 eye for of 1 eye.");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36.

Link to the challenge:

Your regex remove everything is not a letter ( a lowercase one).
It means you can’t check correctly any statement with any character that is not a lowercase letter ( there are two digits in your example) ^^

Your regex discards any value that isn’t a letter.

Read this part of the challenge and modify your regex:

We’ll also pass strings with special symbols, such as “2A33a2", “2A3 3a2”, and "2_A33#A2”

Here is a medium page that you will definitely find useful:

1 Like

gotcha I just change the regex to not include the numbers and it worked,… Thanks both you guys!


My apologies for resurrecting an older thread but I just wanted to point out that I was struggling to understand why my code wasn’t working until I found this post with a link to the regex article in it.

Thank you very much for that - it quite literally saved me hours of searching and pulling out my hair (which is already gone :smiley:)

I was able to complete the Palindrome project successfully after finding this post!