Last active
August 29, 2015 14:04
-
-
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
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
// 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