From 80f7881a26cad546831772fbd3e960bceee77bf0 Mon Sep 17 00:00:00 2001 From: fruddenfeldt <80771026+fruddenfeldt@users.noreply.github.com> Date: Tue, 6 Jun 2023 23:01:36 +0200 Subject: [PATCH 1/2] New solution to match updated test syntax See separate PR "Removed array syntax in multiply test #359" https://github.com/TheOdinProject/javascript-exercises/pull/359 --- 08_calculator/solution/calculator-solution.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/08_calculator/solution/calculator-solution.js b/08_calculator/solution/calculator-solution.js index 0a247ec..dcec19e 100644 --- a/08_calculator/solution/calculator-solution.js +++ b/08_calculator/solution/calculator-solution.js @@ -10,11 +10,13 @@ const sum = function (array) { return array.reduce((total, current) => total + current, 0); }; -const multiply = function (array) { - return array.length - ? array.reduce((accumulator, nextItem) => accumulator * nextItem) - : 0; -}; +const multiply = function(...args){ + let sum = 1 + for (let i = 0; i < args.length; i++) { + sum *= args[i] + } + return sum + } const power = function (a, b) { return Math.pow(a, b); From 175ee761e1777e86c4745dd74b62ebfb9af50cdf Mon Sep 17 00:00:00 2001 From: fruddenfeldt <80771026+fruddenfeldt@users.noreply.github.com> Date: Wed, 7 Jun 2023 19:58:54 +0200 Subject: [PATCH 2/2] Update calculator-solution.js --- 08_calculator/solution/calculator-solution.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/08_calculator/solution/calculator-solution.js b/08_calculator/solution/calculator-solution.js index dcec19e..ab39a60 100644 --- a/08_calculator/solution/calculator-solution.js +++ b/08_calculator/solution/calculator-solution.js @@ -11,12 +11,12 @@ const sum = function (array) { }; const multiply = function(...args){ - let sum = 1 - for (let i = 0; i < args.length; i++) { - sum *= args[i] - } - return sum - } + let product = 1; + for (let i = 0; i < args.length; i++) { + product *= args[i]; + } + return product; + }; const power = function (a, b) { return Math.pow(a, b);