diff --git a/calculator/calculator.js b/calculator/calculator.js index be09295..660e58a 100644 --- a/calculator/calculator.js +++ b/calculator/calculator.js @@ -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,