Update calculator.js
This commit is contained in:
parent
83a2b6aead
commit
d63ee47dcb
1 changed files with 12 additions and 1 deletions
|
@ -19,6 +19,17 @@ function power(a, b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function factorial(n) {
|
function factorial(n) {
|
||||||
|
if (n == 0) return 1;
|
||||||
|
let product = 1;
|
||||||
|
for (let i = n; i > 0; i--) {
|
||||||
|
product *= i;
|
||||||
|
}
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is another implementation of Factorial that uses recursion
|
||||||
|
// THANKS to @ThirtyThreeB!
|
||||||
|
function recursiveFactorial(n) {
|
||||||
if (n===0){
|
if (n===0){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue