Last active
May 29, 2020 15:46
-
-
Save mjmeilahn/773952e612570ebd3f823f82ffc62e2d to your computer and use it in GitHub Desktop.
JS: Palindrome Function
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
// Takes a single string and returns a boolean whether it is the same forwards or backwards | |
// EXAMPLE: | |
// "oscar" -> false | |
// "aaaa" -> true | |
// "Racecar" -> true | |
// "Madam, I'm Adam" -> true | |
// Args: string | |
// Return: boolean | |
const palindrome = str => { | |
const clean = str.toLowerCase().replace(/( )|[.,'\/#!$%\^&\*;:{}=\-_`~\(\)]/g, ""); | |
const final = clean.split('').reverse().join(''); | |
return clean === final; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment