Last active
May 23, 2018 03:31
-
-
Save denismcdonald/b7e1038dcd71d093d8008503d2aeac2b to your computer and use it in GitHub Desktop.
Check to see if string contains palindrome (JavaScript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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