Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. function palindrome(word) {
  2. if (word.length < 2) return true;
  3.  
  4. const lastIndex = word.length - 1;
  5. const indexBeforeLast = word.length - 2;
  6.  
  7. return word[0] == word[lastIndex] && palindrome(word.substr(1, indexBeforeLast));
  8. }
  9.  
  10. console.log("empty:", palindrome(""));
  11. console.log("a:", palindrome("a"));
  12. console.log("aa:", palindrome("aa"));
  13. console.log("ab:", palindrome("ab"));
  14. console.log("abb:", palindrome("abb"));
  15. console.log("aba:", palindrome("aba"));
  16. console.log("abba:", palindrome("abba"));
  17. console.log("abaa:", palindrome("abaa"));
  18. console.log("abcdedcba", palindrome("abcdedcba"));
  19. console.log("abcdeecba", palindrome("abcdeecba"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement