JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Tell us what’s happening:

palindrome(“1 eye for of 1 eye.”) should return false.
why this input should return false?
According to the question this input should return true.

Your code so far

function palindrome(str) {
  str = str.toLowerCase();
  let regex = /[a-z]/g;
  let result = [];
  let flag  = true;
   for(let i=0;i<str.length;i++)
   {
     if(str[i].match(regex))
     {
       result.push(str[i]);
     }
   }
  //  console.log(result.join(""));
   let len = result.length;
   for(let i=0;i<len/2;i++)
   {
     console.log(result[i], result[len-1-i]);
     if(result[i] !== result[len-1-i])
     {
       flag = false;
       break;
     }
   }
  return flag;
}
console.log(palindrome("almostomla"));

Your browser information:

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

Challenge Information:

JavaScript Algorithms and Data Structures Projects - Palindrome Checker

You’ll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.

it says non-alphanumeric characters. So you shouldn’t match a-z only.

1 Like

Thank you sir! for your immediate response with solution to my problem. It means a lot

1 Like

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