Last active
August 29, 2015 14:10
-
-
Save bignimbus/15d62987b65764dff044 to your computer and use it in GitHub Desktop.
detects whether a string is a palindrome
This file contains hidden or 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 isPalindrome (str) { | |
if (typeof str !== 'string') { | |
return false; | |
} | |
var n, | |
letters = str.split(''), | |
len = letters.length - 1; | |
for (n = 0; n <= len; n++) { | |
if (n !== len - n && letters[n] !== letters[len - n]) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment