Created
January 7, 2015 04:49
-
-
Save joyeecheung/bacc5ff91b11b1283c99 to your computer and use it in GitHub Desktop.
Reverse a sequence(array or string) recursively.
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 reverse(seq) { | |
if (seq.length > 1) | |
return seq.slice(-1).concat(reverse(seq.slice(0, -1))); | |
else | |
return seq; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment