Last active
January 12, 2018 06:44
-
-
Save Joejhorn/200cf983c942c37f1dc2591d828722b4 to your computer and use it in GitHub Desktop.
Palindromes - freecodecamp algorithm challenge
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) { | |
| console.log(str); | |
| var strLowerStripped = str.toLowerCase().replace(/[^a-zA-Z0-9]+/g,''); | |
| //split the string into an array | |
| var splitString = strLowerStripped.split(""); | |
| //reverse the string | |
| splitString.reverse(); | |
| //join the arry back together | |
| var joinArray = splitString.join(""); | |
| console.log(joinArray); | |
| console.log(strLowerStripped); | |
| if (joinArray === strLowerStripped){ | |
| return true; | |
| } | |
| 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