From 03e52ea9ee6a5c323d61d71c7164177e5b47372b Mon Sep 17 00:00:00 2001 From: cats256 <59489624+cats256@users.noreply.github.com> Date: Tue, 4 Jul 2023 11:55:08 -0500 Subject: [PATCH] Improve sum and multiply functions solution code --- 08_calculator/solution/calculator-solution.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/08_calculator/solution/calculator-solution.js b/08_calculator/solution/calculator-solution.js index b6b7cf7..43af44f 100644 --- a/08_calculator/solution/calculator-solution.js +++ b/08_calculator/solution/calculator-solution.js @@ -7,16 +7,12 @@ const subtract = function (a, b) { }; const sum = function (...args) { - return args.reduce((total, current) => total + current, 0); + return args.reduce((sum, curr) => sum + curr, 0); }; const multiply = function(...args){ - let product = 1; - for (let i = 0; i < args.length; i++) { - product *= args[i]; - } - return product; - }; + return args.reduce((product, curr) => product * curr) +}; const power = function (a, b) { return Math.pow(a, b);