Check if word or phrase a palindrome (reads the same left to right & vis a vis)
function palindrome(str) {
// convert string to lowercase and replace characters with ""
// split into array then reverse and join back up
// finally compare ArrayStrRev to strLowered
strLowered = str.toLowerCase().replace(/[_:(-/,.\s]+/g, "");
strRev = strLowered.split("");
var ArrayStrRev = strRev.reverse().join("");
if (strLowered === ArrayStrRev) {
return true;
}else{
return false;
}
}
palindrome("race car");