Skip to content

Commit 8692f0e

Browse files
authored
Merge pull request #364 from fruddenfeldt/dev
New solution to match updated test syntax
2 parents 6b302e3 + 175ee76 commit 8692f0e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

08_calculator/solution/calculator-solution.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ const sum = function (array) {
1010
return array.reduce((total, current) => total + current, 0);
1111
};
1212

13-
const multiply = function (array) {
14-
return array.length
15-
? array.reduce((accumulator, nextItem) => accumulator * nextItem)
16-
: 0;
17-
};
13+
const multiply = function(...args){
14+
let product = 1;
15+
for (let i = 0; i < args.length; i++) {
16+
product *= args[i];
17+
}
18+
return product;
19+
};
1820

1921
const power = function (a, b) {
2022
return Math.pow(a, b);

0 commit comments

Comments
 (0)