Is there a better way to do partial sums of array items in JavaScript? Is there a better way to do partial sums of array items in JavaScript? arrays arrays

Is there a better way to do partial sums of array items in JavaScript?


Much, by keeping a running total:

function* partialSums(iterable) {    let s = 0;    for (const x of iterable) {        s += x;        yield s;    }}const x = [0, 1, 2, 3, 4, 5];console.log(Array.from(partialSums(x)).join(', '));