Corrected solution to factorial function
This commit is contained in:
parent
35ed3d7b44
commit
83a2b6aead
1 changed files with 4 additions and 6 deletions
|
@ -19,12 +19,10 @@ function power(a, b) {
|
|||
}
|
||||
|
||||
function factorial(n) {
|
||||
if (n == 0) return 0;
|
||||
let product = 1;
|
||||
for (let i = n; i > 0; i--) {
|
||||
product *= i;
|
||||
if (n===0){
|
||||
return 1;
|
||||
}
|
||||
return product;
|
||||
return n * factorial (n-1);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Reference in a new issue