Skip to content

Instantly share code, notes, and snippets.

@baranovxyz
Created May 9, 2020 21:01
Show Gist options
  • Save baranovxyz/333fd7b4f25b659766d1498726f42971 to your computer and use it in GitHub Desktop.
Save baranovxyz/333fd7b4f25b659766d1498726f42971 to your computer and use it in GitHub Desktop.
const factorial = trampoline(function _factorial(n, acc = 1) {
if (n <= 1) return acc;
return () => _factorial(n - 1, n * acc);
});
console.log(factorial(5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment