Skip to content

Instantly share code, notes, and snippets.

@TravelingMan
Last active January 12, 2016 01:57
Show Gist options
  • Save TravelingMan/ca8a878ba384202addc2 to your computer and use it in GitHub Desktop.
Save TravelingMan/ca8a878ba384202addc2 to your computer and use it in GitHub Desktop.
Palindrome finder
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