Skip to content

Instantly share code, notes, and snippets.

@premithk
Created December 21, 2017 17:37
Show Gist options
  • Save premithk/7bbd35c07d4ce4352e4c0af0c35f68ee to your computer and use it in GitHub Desktop.
Save premithk/7bbd35c07d4ce4352e4c0af0c35f68ee to your computer and use it in GitHub Desktop.
Recursive and Linear Recursive created by Premith - https://repl.it/@Premith/Recursive-and-Linear-Recursive
const factorial = n => (n === 0 ? 1 : n * factorial(n - 1));
const factorial_iter = n => fact_iter(1, 1, n);
const fact_iter = (product, counter, max) => {
return counter > max
? product
: fact_iter(counter * product, counter + 1, max);
};
factorial(6);
factorial_iter(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment