Palindrome Checker true wont pass the test

Tell us what’s happening:

Your code so far


function palindrome(str) {
  // Good luck!
  str = str.toLowerCase();
  let characterArr = str.split("");
  let validCharacters = "abcdefghijklmnopqrstuvwxyz".split("");

  let lettersArr = [];
  characterArr.forEach(function(char){
    if(validCharacters.indexOf(char) > -1){
      lettersArr.push(char);
    };
  });
  if(lettersArr.join("") === lettersArr.reverse().join()) return true
   else return false;
}



palindrome("eye");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker

I will give you a hint with the following part of the instructions.

You’ll need to remove all non-alphanumeric characters (punctuation, spaces and symbols)

Make sure you understand what alphanumeric means before adding the non in front of it.

Also, there is a problem with the second join.

if(lettersArr.join("") === lettersArr.reverse().join()) return true
2 Likes