8000 Improve sum and multiply functions solution code · MysticRiver/javascript-exercises@03e52ea · GitHub
[go: up one dir, main page]

Skip to content

Commit 03e52ea

Browse files
committed
Improve sum and multiply functions solution code
1 parent 075fe8e commit 03e52ea

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

08_calculator/solution/calculator-solution.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ const subtract = function (a, b) {
77
};
88

99
const sum = function (...args) {
10-
return args.reduce((total, current) => total + current, 0);
10+
return args.reduce((sum, curr) => sum + curr, 0);
1111
};
1212

1313
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-
};
14+
return args.reduce((product, curr) => product * curr)
15+
};
2016

2117
const power = function (a, b) {
2218
return Math.pow(a, b);

0 commit comments

Comments
 (0)
0