Skip to content

Instantly share code, notes, and snippets.

@denismcdonald
Last active May 23, 2018 03:31
Show Gist options
  • Save denismcdonald/b7e1038dcd71d093d8008503d2aeac2b to your computer and use it in GitHub Desktop.
Save denismcdonald/b7e1038dcd71d093d8008503d2aeac2b to your computer and use it in GitHub Desktop.
Check to see if string contains palindrome (JavaScript)
function palindrome(str) {
var strAlt = str.toLowerCase();
strAlt = strAlt.replace(/\s/g, "");
strAlt = strAlt.replace(/\W/g, "");
strAlt = strAlt.replace(/_/g, "");
if (strAlt.split("").reverse().join("") == strAlt) {
return true;
} else {
return false;
}
}
palindrome("1 eye_ for of 1 eye.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment