From 83a2b6aead81052661e9459f605b1b07789d309d Mon Sep 17 00:00:00 2001 From: ThirtyThreeB Date: Wed, 3 Jan 2018 12:10:49 -0500 Subject: [PATCH] Corrected solution to factorial function --- calculator/calculator.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/calculator/calculator.js b/calculator/calculator.js index be09295..8ad98c0 100644 --- a/calculator/calculator.js +++ b/calculator/calculator.js @@ -19,12 +19,10 @@ function power(a, b) { } function factorial(n) { - if (n == 0) return 0; - let product = 1; - for (let i = n; i > 0; i--) { - product *= i; - } - return product; + if (n===0){ + return 1; +} + return n * factorial (n-1); } module.exports = {