Reduce 1
Important Links
Clientside problem (opens in a new tab)
The coding train - Reduce (opens in a new tab)
exWithOutReduce.js
let vals = [1,2,3,4,5];
let sum = 0;
// let acc represent sum
...
for (let i=0; i < vals.length; i++) {
sum += vals[i];
}
...
for (let val of vals) {
sum += val;
}
...
function sum(acc, val) {
return acc + val;
}
let answer = vals.reduce(sum);
console.log(sum)