Why can't i pass "1 eye for of 1 eye." test?

Tell us what’s happening:
If we format it, it will look like : eyeforofeye
If we reverse that, we get: eyeforofeye

Why is this not working? Thanks.f

  **Your code so far**

function palindrome(str) {
let reg=/[^a-zA-Z\t]/gi;
let formated = str.replace(reg,"").toLowerCase();
let copy = formated.slice();
let reverse = "";
let result;

for(let i=copy.length-1;i>=0;i--){

result = reverse.localeCompare(formated);

if(result == 0){
return true;
else if(result == 1 || result ==-1){
return false;


  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36

Challenge: Palindrome Checker

Link to the challenge:

Hey there and welcome to the forums :wave: :slightly_smiling_face:

Note the instructions:

You’ll need to remove all non-alphanumeric characters

By taking a look at copy and reverse, with some console.log()s, you’ll notice your regex is removing more than it should be.

Thank you! I just noticed too… I didn’t include 0-9 on my regex…

1 Like