Last active
January 12, 2016 01:57
-
-
Save TravelingMan/ca8a878ba384202addc2 to your computer and use it in GitHub Desktop.
Palindrome finder
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 palStr = str.replace(/\W/g, "").toLowerCase(); // Use /[\W_]/g to remove underscores too | |
for (var i = 0; i < palStr.length; i++) { | |
if (palStr[i] != palStr[palStr.length - 1 - i]) { | |
return false; | |
} | |
} | |
return true; | |
} | |
palindrome("racecar"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment