https://www.w3schools.com/jsref/jsref_reduce.asp
array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
Add up items
var stuff = [10,15,5,20]
var totalstuff = stuff.reduce(addup,0);
function addup(total, currentval) {
return total + currentval;
}
Same thing
var stuff = [10,15,5,20]
var totalstuff = stuff.reduce(function(total, currentval) {
return total + currentval;
},0);
Same thing
var stuff = [10,15,5,20]
var totalstuff = stuff.reduce((total, currentval)=> total + currentval , 0);