const sumAll = function (min, max) {
const allSums = [];
const initialValue = 0;
for (let i = min; i <= max; i++) {
allSums.push([i]);
}
console.log(allSums); //
let sumTotal = allSums.reduce(function (acc, curr) {
acc += curr;
return acc;
}, initialValue);
console.log(sumTotal);
};
sumAll(1, 4) returns 01234 instead of 10.
I can see that allSums is 4 arrays inside of an array. How would I go about concatenating them? Thank you for the help!
Via Active questions tagged javascript - Stack Overflow https://ift.tt/4T1qrtd
Comments
Post a Comment