Skip to content

Instantly share code, notes, and snippets.

@nilz3ro
Created February 15, 2017 15:27
Show Gist options
  • Save nilz3ro/ff9e36538de06b6a0b40a96252d58dc5 to your computer and use it in GitHub Desktop.
Save nilz3ro/ff9e36538de06b6a0b40a96252d58dc5 to your computer and use it in GitHub Desktop.
Recursion Example
// 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