Skip to content

Instantly share code, notes, and snippets.

@AndriiBozh
Created January 7, 2018 13:57
Show Gist options
  • Save AndriiBozh/6ca2a2414b0fbccfae984d8aa46b2fb3 to your computer and use it in GitHub Desktop.
Save AndriiBozh/6ca2a2414b0fbccfae984d8aa46b2fb3 to your computer and use it in GitHub Desktop.
Check For Palindromes (freeCodeCamp challenge)
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