Last active
February 24, 2018 11:31
-
-
Save AdrianSkar/21fc62c37ab467caabb3cb4d40e41132 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Requirements: lowercase, non-alphanumeric chars + no underscores | |
function palindrome(str) { | |
str = str.toLowerCase(); | |
str = str.replace(/\W/g, ""); //Remove all non-alphanumeric chars | |
str = str.replace(/_/g, ""); //Remove all underscore chars | |
// All at once -> str = str.toLowerCase().replace(/\W|_/g, ""); | |
if (str == str.split("").reverse().join('')){ // Check | |
return true; // If it's a palindrome | |
} | |
return false; // If it's not | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment