@extra-array/accumulate
Version:
Produces accumulating values.
51 lines (37 loc) • 1.55 kB
Markdown
Produces accumulating values.
[:package:](https://www.npmjs.com/package/@extra-array/accumulate)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/accumulate)
[:vhs:](https://asciinema.org/a/332019)
[:moon:](https://www.npmjs.com/package/@extra-array/accumulate.min)
[:scroll:](https://unpkg.com/@extra-array/accumulate/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Similar: [map], [filter], [reject], [reduce], [accumulate].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.accumulate(x, fr, [acc]);
// x: an array
// fr: reduce function (acc, v, i, x)
// acc: initial value
```
```javascript
const array = require("extra-array");
var x = [1, 2, 3, 4];
array.accumulate(x, (acc, v) => acc+v);
// [ 1, 3, 6, 10 ]
array.accumulate(x, (acc, v) => acc+v, 100);
// [ 101, 103, 106, 110 ]
```
<br>
<br>
## 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)
[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
[reject]: https://github.com/nodef/extra-array/wiki/reject