Created
February 15, 2017 15:27
-
-
Save nilz3ro/ff9e36538de06b6a0b40a96252d58dc5 to your computer and use it in GitHub Desktop.
Recursion Example
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
// One liner. | |
const reverseIt = (string, memo='') => string.length ? reverseIt(string.substr(1), string.substr(0,1) + memo) : memo | |
// same as: | |
function reverseIt2 (string, memo='') { | |
if (string.length) { | |
return reverseIt2(string.substr(1), string.substr(0,1) + memo); | |
} else { | |
return memo; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment