JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Hi There,

I want to know why this is not a pallindrome:
palindrome("1 eye for of 1 eye.") should return false.

i take the letters and it seems to be a pallindrome.

Can Anybody tells me what im not seeing?

  **Your code so far**
function palindrome(str) {
    let regex = /[\W*0-9_-]/gi;
    let word = str.split(regex).join("").toLowerCase();
    let wordRev =[];
    for(let i =word.length-1;i>=0;i--){
      wordRev.push(word[i]);
    }
    return wordRev.every((item, index)=>(item === word[index]));
}

  **Your browser information:**

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

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

The rules stated are that we remove everything that isn’t a letter or a number (alphanumeric). So, we get this:

1eyeforof1eye

In order to be a palindrome, it has to be the same forward and backwards. The backwards version of that string is:

eye1forofeye1

Those are not the same, so this is not a palindrome.

Another way to think of it is that the first character must be the same as the last character: “1” and “e” are not the same. And the second character must be the same as the second to last, and the third character…

Does that all makes sense?

You could say that “1 eye for of 1 eye” is kind of a phonetic palindrome, or perhaps by groups of words, if we group certain sounds or words together. It has “one eye” then “for of” then “one eye”. But that is really stretching the definition of palindrome to the point where it breaks.

Thanks! i had that wrong :smiley:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.