@extra-array/accumulate-update
Version:
Produces accumulating values.
50 lines (40 loc) • 1.8 kB
Markdown
Produces accumulating values. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:]
> Alternatives: [accumulate], [accumulate$].<br>
> Similar: [map], [filter], [reduce], [accumulate].<br>
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
```javascript
array.accumulate$(x, fn, [acc]);
// x: an array (updated)
// fn: reduce function (acc, v, i, x)
// acc: initial value
// --> x
```
```javascript
const array = require('extra-array');
var x = [1, 2, 3, 4];
array.accumulate$(x, (acc, v) => acc+v);
// [ 1, 3, 6, 10 ]
x;
// [ 1, 3, 6, 10 ]
var x = [1, 2, 3, 4];
array.accumulate$(x, (acc, v) => acc+v, 100);
// [ 101, 103, 106, 110 ]
```
### references
- [Data.List.scanl: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:scanl)
- [itertools.accumulate: Python](https://docs.python.org/3/library/itertools.html#itertools.accumulate)
[:running:]: https://npm.runkit.com/@extra-array/accumulate
[:package:]: https://www.npmjs.com/package/@extra-array/accumulate
[:moon:]: https://www.npmjs.com/package/@extra-array/accumulate.min
[:ledger:]: https://unpkg.com/@extra-array/accumulate/
[accumulate]: https://github.com/nodef/extra-array/wiki/accumulate
[accumulate$]: https://github.com/nodef/extra-array/wiki/accumulate$
[map]: https://github.com/nodef/extra-array/wiki/map
[filter]: https://github.com/nodef/extra-array/wiki/filter
[reduce]: https://github.com/nodef/extra-array/wiki/reduce
[:running:]: https://npm.runkit.com/@extra-array/accumulate-update
[:package:]: https://www.npmjs.com/package/@extra-array/accumulate-update
[:moon:]: https://www.npmjs.com/package/@extra-array/accumulate-update.min
[:ledger:]: https://unpkg.com/@extra-array/accumulate-update/
[:vhs:]: https://asciinema.org/a/332018