Skip to content

Instantly share code, notes, and snippets.

@notbrain
Created January 3, 2011 02:46
Show Gist options
  • Save notbrain/763061 to your computer and use it in GitHub Desktop.
Save notbrain/763061 to your computer and use it in GitHub Desktop.
// 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;
}
@notbrain
Copy link
Author

notbrain commented Jan 3, 2011

Was asked this for a whiteboarding interview once, wanted to give it an honest shot. Is there any more efficient way to do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment