Skip to content

Instantly share code, notes, and snippets.

@panicbus
Created October 20, 2016 18:42
Show Gist options
  • Save panicbus/f382585162e93d1f98a7bd77cb462200 to your computer and use it in GitHub Desktop.
Save panicbus/f382585162e93d1f98a7bd77cb462200 to your computer and use it in GitHub Desktop.
Find whether a string is a palindrome
function isPalindrome(str){
var nospace = str.split(' ').join('');
var len = nospace.length;
for (var i = 0; i < len/2; i++) {
if (nospace[i] !== nospace[len -1 -i])
return false;
}
return true;
}
isPalindrome('he, a man a plan a canal panama, eh');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment