Palindrome Checker Help

Palindrome Checker Help
0

#1

Tell us what’s happening:
I know I have a issue when I try to filter the correct characeter. I think my regex expresion is right but I don’t know if regex isn’t compatible with filter or something.

I’m missing something and I not sure what it is…

Your code so far


function palindrome(str) {
  let myFilter = str.split("").filter((i) => i == /[a-z]/gi )
  console.log(myFilter);
  let strFilter = myFilter.join("").toLowerCase();
  let myReverse = myFilter.reverse().join("").toLowerCase();
  if (strFilter == myReverse) {
    return true
  }
  return false;
}



palindrome("A man, a plan, a canal. Panama");

Your browser information:

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

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


#2

You are trying to compare i with a regular expression. Regular expression are objects and i is a string. Those data types will never be equal. I think you are wanting to test the regular expression with the string i. You can write the following regular expression (without the global flag). This would test if i is a letter a-z or A-Z and return a true or false value.

/[a-z]/i.test(i)