New solution to match updated test syntax

See separate PR "Removed array syntax in multiply test #359"  

https://github.com/TheOdinProject/javascript-exercises/pull/359
This commit is contained in:
fruddenfeldt 2023-06-06 23:01:36 +02:00 committed by GitHub
parent 3e530e3f61
commit 80f7881a26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,11 +10,13 @@ const sum = function (array) {
return array.reduce((total, current) => total + current, 0); return array.reduce((total, current) => total + current, 0);
}; };
const multiply = function (array) { const multiply = function(...args){
return array.length let sum = 1
? array.reduce((accumulator, nextItem) => accumulator * nextItem) for (let i = 0; i < args.length; i++) {
: 0; sum *= args[i]
}; }
return sum
}
const power = function (a, b) { const power = function (a, b) {
return Math.pow(a, b); return Math.pow(a, b);