Last active
January 21, 2019 13:51
-
-
Save aykutyaman/5eb82000277ea74b2a89729ec1cb0ce6 to your computer and use it in GitHub Desktop.
Recursive 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
// it works only with strings | |
const isPalindrome = ([head, ...tail]) => { | |
if (tail.length === 0) return true | |
if (head !== tail[tail.length - 1]) return false | |
return isPalindrome(tail.slice(0, tail.length - 1)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment