Merge pull request #9 from ThirtyThreeB/patch-1
Corrected solution to factorial function
This commit is contained in:
commit
b14ac4ea17
1 changed files with 10 additions and 1 deletions
|
@ -19,7 +19,7 @@ function power(a, b) {
|
|||
}
|
||||
|
||||
function factorial(n) {
|
||||
if (n == 0) return 0;
|
||||
if (n == 0) return 1;
|
||||
let product = 1;
|
||||
for (let i = n; i > 0; i--) {
|
||||
product *= i;
|
||||
|
@ -27,6 +27,15 @@ function factorial(n) {
|
|||
return product;
|
||||
}
|
||||
|
||||
// This is another implementation of Factorial that uses recursion
|
||||
// THANKS to @ThirtyThreeB!
|
||||
function recursiveFactorial(n) {
|
||||
if (n===0){
|
||||
return 1;
|
||||
}
|
||||
return n * factorial (n-1);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add,
|
||||
subtract,
|
||||
|
|
Loading…
Reference in a new issue