Skip to content

Instantly share code, notes, and snippets.

@web20opensource
Last active August 29, 2015 14:17
Show Gist options
  • Save web20opensource/cd6bcfcd8627864fe2d9 to your computer and use it in GitHub Desktop.
Save web20opensource/cd6bcfcd8627864fe2d9 to your computer and use it in GitHub Desktop.
Check if a given text is a palindrome
var isPalindrome = function(text){
while(text.length!=1){
var firstChar = text.charAt(0);
var lastChar = text.charAt(text.length-1);
if (firstChar===lastChar){
text = text.substr(1,text.length-2);
}
else{
return false;
}
}
return true;
};
console.log("is 'rotator' a palindrome word ? : " + isPalindrome("rotator"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment