Created
June 21, 2016 14:03
-
-
Save brainyfarm/83f45606251f559e67f3b158f1a4253e to your computer and use it in GitHub Desktop.
Olawale/FreeCodeCamp: Check for Palindromes
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
function palindrome(str) { | |
// Rid the string of anything not letters or numbers | |
var cleaned = str.toLowerCase().replace(/[^a-z0-9]/g, ""); | |
// Compare the cleaned string to iteself but in a reverse direction, return true or false | |
return (cleaned === cleaned.split("").reverse().join("")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment