Skip to content

Instantly share code, notes, and snippets.

@leolanese
Created April 19, 2019 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leolanese/06acd13f5ac1d78615065044c71a2a7e to your computer and use it in GitHub Desktop.
Save leolanese/06acd13f5ac1d78615065044c71a2a7e to your computer and use it in GitHub Desktop.
function isPalindrome(str) {
str = str.replace(/\W/g, '').toLowerCase();
return (str == str.split('').reverse().join(''));
}
console.log(isPalindrome("level")); // logs 'true'
console.log(isPalindrome("levels")); // logs 'false'
console.log(isPalindrome("A car, a man, a maraca")); // logs 'true'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment