Skip to content

Instantly share code, notes, and snippets.

@olarclara
Created April 13, 2017 15:36
Show Gist options
  • Save olarclara/3ed83d1d5c7c5c6e02fd299ee1beb20f to your computer and use it in GitHub Desktop.
Save olarclara/3ed83d1d5c7c5c6e02fd299ee1beb20f to your computer and use it in GitHub Desktop.
function factorial(n) {
if (!n) return 1;
return n * factorial(n-1);
}
function factorialTCO(n, partialFactorial = 1) {
if (!n)
return partialFactorial;
return factorialTCO(n - 1, n * partialFactorial);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment