Skip to content

Instantly share code, notes, and snippets.

@djleonskennedy
Last active July 17, 2017 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djleonskennedy/43c3731b52d17e6a712d0bdeabe76aa7 to your computer and use it in GitHub Desktop.
Save djleonskennedy/43c3731b52d17e6a712d0bdeabe76aa7 to your computer and use it in GitHub Desktop.
recursion
// Recursive:
const factorial = n =>
n < 2
? 1
: n * factorial(n-1);
// Tail-recursive:
const factorial = n => {
const _tempFactorial = (n, acc) =>
n < 2
? acc
: _tempFactorial(n-1, n * acc)
return _tempFactorial(n, 1)
}
@djleonskennedy
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment