From d63ee47dcbb0f7b143f72706366e504bad3ae95d Mon Sep 17 00:00:00 2001 From: Cody Loyd Date: Wed, 3 Jan 2018 12:21:25 -0600 Subject: [PATCH] Update calculator.js --- calculator/calculator.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/calculator/calculator.js b/calculator/calculator.js index 8ad98c0..660e58a 100644 --- a/calculator/calculator.js +++ b/calculator/calculator.js @@ -19,9 +19,20 @@ function power(a, b) { } 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){ return 1; -} + } return n * factorial (n-1); }