-
Notifications
You must be signed in to change notification settings - Fork 5
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
// fr: reduce function (acc, v, i, x)
// acc: initial value
const xarray = require('extra-array');
var x = [1, 2, 3, 4, 5];
var y = xarray.inclusiveScan(x, (acc, v) => acc+v, 0);
// → [ 1, 3, 6, 10, 15 ]
var y = xarray.inclusiveScan(x, (acc, v) => acc+v, 10);
// → [ 11, 13, 16, 20, 25 ]