Created
September 20, 2017 03:15
-
-
Save vvgomes/b19a2f0134bbda9b79e1414889d4dec0 to your computer and use it in GitHub Desktop.
This file contains 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 palindrome(word) { | |
if (word.length < 2) return true; | |
const lastIndex = word.length - 1; | |
const indexBeforeLast = word.length - 2; | |
return word[0] == word[lastIndex] && palindrome(word.substr(1, indexBeforeLast)); | |
} | |
console.log("empty:", palindrome("")); | |
console.log("a:", palindrome("a")); | |
console.log("aa:", palindrome("aa")); | |
console.log("ab:", palindrome("ab")); | |
console.log("abb:", palindrome("abb")); | |
console.log("aba:", palindrome("aba")); | |
console.log("abba:", palindrome("abba")); | |
console.log("abaa:", palindrome("abaa")); | |
console.log("abcdedcba", palindrome("abcdedcba")); | |
console.log("abcdeecba", palindrome("abcdeecba")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment