Skip to content

Instantly share code, notes, and snippets.

@leandrooriente
Last active January 16, 2020 00:39
Show Gist options
  • Save leandrooriente/3403359aadad88824d57 to your computer and use it in GitHub Desktop.
Save leandrooriente/3403359aadad88824d57 to your computer and use it in GitHub Desktop.
Palíndromo recursivo mais elegante do universo em javascript
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;
}
@Luan4560
Copy link

Luan4560 commented Apr 4, 2019

outra maneira
function checkPalindrome(word) {
return word == word.split('').reverse().join('');
};

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