JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Hello and thanks in advance for your help.

I am failing 2 out of the 13 tests, and I can’t figure out how to fix my code to pass these 2 as well.

Thanks,
Shawn Wright

// Failed: palindrome("A man, a plan, a canal. Panama") should return true.
// Failed: palindrome("My age is 0, 0 si ega ym.") should return true.
function palindrome(str) {
  let tempStr = str.replace(/[^\p{L}\d]/gu, '');
  let newStr = tempStr.split("").reverse().join("");

  if(newStr === tempStr) {
    return true;
  } else {
  return false;
  }
}
palindrome("eye");

// I also tried reg. expr. for tempStr = str.replace(/[\W_]/g, ''); 
// I also tried reg. expr. for tempStr = str.replace(/[^A-Za-z0-9]/g, '');

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

Consider this test case:

palindrome("Eye");

So the captial letters are my down fall it seems.

Ok I thought one of those regex I tried covered that, but clearly not.
I guess it’s back to the drawing board.

Thanks @JeremyLT

You don’t need a regex to convert capital letters to lowercase.

1 Like

Oh, that’s right… da. I feel stupid.
Thanks, @JeremyLT

Sometimes you need somebody looking at the box from a different angle :slight_smile:

1 Like

Well said!
Hi five!
/*
Bug: I hate coding
Bug: I hate coding
Bug: I hate coding
Bug pointed out
I LOVE coding!
*/
:sweat_smile:

1 Like

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