Skip to content

inclusiveScan$

Subhajit Sahu edited this page May 3, 2023 · 1 revision

Perform inclusive prefix scan from left to right!

Alternatives: inclusiveScan, inclusiveScan$.
Similar: inclusiveScan, exclusiveScan.


function inclusiveScan$(x, fr, acc)
// x:   an array (updated!)
// fr:  reduce function (acc, v, i, x)
// acc: initial value

const xarray = require('extra-array');

var x = [1, 2, 3, 4, 5];
xarray.inclusiveScan$(x, (acc, v) => acc+v, 0);
// → [ 1, 3, 6, 10, 15 ]  (x modified!)

var x = [1, 2, 3, 4, 5];
xarray.inclusiveScan$(x, (acc, v) => acc+v, 10);
// → [ 11, 13, 16, 20, 25 ]  (x modified!)


References

Clone this wiki locally