JavaScript Algorithms and Data Structures Projects - Palindrome Checker

I tried solving the palindrome checker code and all test cases pass except the one with the “0_0 ( : /-\ : ) 0-0” string. It says palindrome(“0_0 ( : /-\ : ) 0-0”) should return true` but why should it return true when it is not a palindrome. Shouldn’t it return false?

Your code so far

function palindrome(str) {
  let regex=/[^.,_:\s]/gi;
  let str1=str.match(regex).join().toLowerCase();
  let newStr1=str.split("").reverse().join();
  let str2=newStr1.match(regex).join().toLowerCase();
  
  for(let i=0;i<str.length;i++){
    if(str1[i]!==str2[i]){
      return false;
    }
  }
  return true;
  
}
palindrome("eye");

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Your checker should ignore ALL non-alphanumeric characters when determining whether the string is a palindrome or not.
You have a regex which removes only a very limited set of non-alphanumeric characters.

So, "0_0 (: /-\ :) 0-0" is palindromic, as the string without non-alphanumeric characters is "0000".

Thank you. I figured it out.

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