Created
January 3, 2011 02:46
-
-
Save notbrain/763061 to your computer and use it in GitHub Desktop.
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
// 1234567 | |
// racecar | |
// 0123456 | |
// >>>X<<< close in on it, only need half the length of word loopage | |
function is_palindrome(word) { | |
var outcome = true; | |
for(i = 0; i <= (word.length / 2); i++) { | |
//console.log("Comparing " + word[i] + " and " + word[word.length - 1 - i] + "." ); | |
// always true for palindromes | |
if(word[i] != word[word.length - 1 - i]) { | |
outcome = false; | |
break; | |
} | |
} | |
return outcome; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Was asked this for a whiteboarding interview once, wanted to give it an honest shot. Is there any more efficient way to do this?