Created
January 7, 2018 13:57
-
-
Save AndriiBozh/6ca2a2414b0fbccfae984d8aa46b2fb3 to your computer and use it in GitHub Desktop.
Check For Palindromes (freeCodeCamp challenge)
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 result = str.replace(/[\W_]/g, '').toLowerCase(); // find and remove all non-alphanumeric characters (punctuation, spaces and symbols) from a string, replace them with ''(no-space), and turn everything lower case | |
var reversed = result.split('').reverse().join(''); // split a "result" into an array of strings (separator is '', no-space), reverse it and join all elements of an array into a string and return this string. | |
if (reversed === result) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
palindrome("eye"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment