Last active
January 16, 2020 00:39
-
-
Save leandrooriente/3403359aadad88824d57 to your computer and use it in GitHub Desktop.
Palíndromo recursivo mais elegante do universo em javascript
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
function palindrome (word){ | |
var len = word.length, | |
lastCharIndex = len - 1; | |
if (len === 0 || len === 1) { | |
return true; | |
} | |
if (word[0] === word[lastCharIndex]) { | |
word = word.substr(0, lastCharIndex).substr(1); | |
return palindrome(word); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
outra maneira
function checkPalindrome(word) {
return word == word.split('').reverse().join('');
};