Improve sum and multiply functions solution code

This commit is contained in:
cats256 2023-07-04 11:55:08 -05:00
parent 075fe8eea2
commit 03e52ea9ee
1 changed files with 3 additions and 7 deletions

View File

@ -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);