Skip to content

Commit 80f7881

Browse files
authored
New solution to match updated test syntax
See separate PR "Removed array syntax in multiply test #359" #359
1 parent 3e530e3 commit 80f7881

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 sum = 1
15+
for (let i = 0; i < args.length; i++) {
16+
sum *= args[i]
17+
}
18+
return sum
19+
}
1820

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

0 commit comments

Comments
 (0)