This is an example of what I need to do:
var myarray = [5, 10, 3, 2]; var result1 = myarray[0]; var result2 = myarray[1] + myarray[0]; var result3 = myarray
Use arrow function instead of function, comma operator instead of return, and currentIndex in reduce callback.
[5, 10, 3, 2].reduce((r, a, i) => (r.push((i && r[i - 1] || 0) + a), r), []); // [ 5, 15, 18, 20 ]