- Notifications
You must be signed in to change notification settings - Fork5
exclusiveScan$
Subhajit Sahu edited this pageMay 3, 2023 ·1 revision
Perform exclusive prefix scan from left to right!
Alternatives:exclusiveScan,exclusiveScan$.
Similar:inclusiveScan,exclusiveScan.
functionexclusiveScan$(x,fr,acc)// x: an array (updated!)// fr: reduce function (acc, v, i, x)// acc: initial value
constxarray=require('extra-array');varx=[1,2,3,4,5];xarray.exclusiveScan$(x,(acc,v)=>acc+v,0);x;// → [ 0, 1, 3, 6, 10 ] (x modified!)varx=[1,2,3,4,5];xarray.exclusiveScan$(x,(acc,v)=>acc+v,10);x;// → [ 10, 11, 13, 16, 20 ] (x modified!)