8000 Corrected solution to factorial function · M-Munk/javascript-exercises@83a2b6a · GitHub
[go: up one dir, main page]

Skip to content

Commit 83a2b6a

Browse files
authored
Corrected solution to factorial function
1 parent 35ed3d7 commit 83a2b6a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

calculator/calculator.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ function power(a, b) {
1919
}
2020

2121
function factorial(n) {
22-
if (n == 0) return 0;
23-
let product = 1;
24-
for (let i = n; i > 0; i--) {
25-
product *= i;
26-
}
27-
return product;
22+
if (n===0){
23+
return 1;
24+
}
25+
return n * factorial (n-1);
2826
}
2927

3028
module.exports = {

0 commit comments

Comments
 (0)
0