accumulate
Creates an array of partial sums.
- Use
Array.prototype.reduce()
, initialized with an empty array accumulator to iterate overnums
. - Use
Array.prototype.slice(-1)
, the spread operator (...
) and the unary+
operator to add each value to the accumulator array containing the previous sums.