Skip to content

Instantly share code, notes, and snippets.

@marcmartino
Created December 23, 2013 22:09
Show Gist options
  • Select an option

  • Save marcmartino/8105706 to your computer and use it in GitHub Desktop.

Select an option

Save marcmartino/8105706 to your computer and use it in GitHub Desktop.
Determine if a given string is a paindrome
function isPalindrome(str) {
var middle = Math.floor(str.length / 2),
m = 0,
strArr = str.toLowerCase().split("");
for (m; m <= middle; m++) {
if (strArr[m] !== strArr[strArr.length - 1 - m]) {
return false;
}
}
return true;
}
console.log(isPalindrome("racecar"),
isPalindrome("broomstick"),
isPalindrome("racecars"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment