8000 Merge pull request #9 from ThirtyThreeB/patch-1 · GeraldCO/javascript-exercises@b14ac4e · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b14ac4e

Browse files
authored
Merge pull request TheOdinProject#9 from ThirtyThreeB/patch-1
Corrected solution to factorial function
2 parents 35ed3d7 + d63ee47 commit b14ac4e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

calculator/calculator.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ function power(a, b) {
1919
}
2020

2121
function factorial(n) {
22-
if (n == 0) return 0;
22+
if (n == 0) return 1;
2323
let product = 1;
2424
for (let i = n; i > 0; i--) {
2525
product *= i;
2626
}
2727
return product;
2828
}
2929

30+
// This is another implementation of Factorial that uses recursion
31+
// THANKS to @ThirtyThreeB!
32+
function recursiveFactorial(n) {
33+
if (n===0){
34+
return 1;
35+
}
36+
return n * factorial (n-1);
37+
}
38+
3039
module.exports = {
3140
add,
3241
subtract,

0 commit comments

Comments
 (0)
0