Improve sum and multiply functions solution code
This commit is contained in:
parent
075fe8eea2
commit
03e52ea9ee
|
@ -7,16 +7,12 @@ const subtract = function (a, b) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const sum = function (...args) {
|
const sum = function (...args) {
|
||||||
return args.reduce((total, current) => total + current, 0);
|
return args.reduce((sum, curr) => sum + curr, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
const multiply = function(...args){
|
const multiply = function(...args){
|
||||||
let product = 1;
|
return args.reduce((product, curr) => product * curr)
|
||||||
for (let i = 0; i < args.length; i++) {
|
};
|
||||||
product *= args[i];
|
|
||||||
}
|
|
||||||
return product;
|
|
||||||
};
|
|
||||||
|
|
||||||
const power = function (a, b) {
|
const power = function (a, b) {
|
||||||
return Math.pow(a, b);
|
return Math.pow(a, b);
|
||||||
|
|
Loading…
Reference in New Issue