Help for "Palindrome Checker"

The following code is not working, some tests are being passed, but some aren’t.

function palindrome(str) {
//remove all non-alphanumeric characters
//turn everything into same lower case 
str.replace(/[\W_]/g, ""); //*

var splitString = str.split("");
var reverseArray = splitString.reverse();
var joinArray = reverseArray.join("");

if (str === joinArray){
  return true;
} else{
  return false; 

  **Your browser information:**

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

Challenge: Palindrome Checker

Link to the challenge:

Does str.toLowerCase() perform the change in place, or does it return a new string?

1 Like

Right, and the same problem with _ replace_.

I always forget which methods change the original and which ones leave the original unchanged but return the new version. I always check the docs. If you search for “mdn string replace”, you will go to Mozilla’s excellent JS reference site.


Thank you, got it now!

1 Like

Another great source (and one to which I’ve always got a tab open) is devdocs ( Pulls from the official mdn docs as well as many others. A great one-stop doc shop!

1 Like

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