Created
December 21, 2017 17:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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