Last active
August 29, 2015 14:17
-
-
Save web20opensource/cd6bcfcd8627864fe2d9 to your computer and use it in GitHub Desktop.
Check if a given text 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
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