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, ""); //*
str.toLowerCase();
var splitString = str.split("");
var reverseArray = splitString.reverse();
var joinArray = reverseArray.join("");
if (str === joinArray){
return true;
} else{
return false;
}
}
palindrome("eye");
**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.
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.
Another great source (and one to which I’ve always got a tab open) is devdocs (https://devdocs.io/). Pulls from the official mdn docs as well as many others. A great one-stop doc shop!