Skip to content

Instantly share code, notes, and snippets.

@jorinvo
Last active August 29, 2015 14:04
Show Gist options
  • Save jorinvo/f0167d6d4496dfec6fa1 to your computer and use it in GitHub Desktop.
Save jorinvo/f0167d6d4496dfec6fa1 to your computer and use it in GitHub Desktop.
Check if string is palindrome. More accurate implementation for http://www.toptal.com/javascript/interview-questions#iquestion-34
// Also handles special characters and uppercase
// like in “Amore, Roma“, “A man, a plan, a canal: Panama” or “No ‘x’ in ‘Nixon’“
// (Unfortunately doesn't fit into 80 chars)
function isPalindrome(str) {
var stripped = str.toLowerCase().replace(/[^a-z]/g, '');
return stripped === stripped.reverse();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment