1 | Produces accumulating values.
|
2 | [:package:](https://www.npmjs.com/package/@extra-array/accumulate)
|
3 | [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
|
4 | [:running:](https://npm.runkit.com/@extra-array/accumulate)
|
5 | [:vhs:](https://asciinema.org/a/332019)
|
6 | [:moon:](https://www.npmjs.com/package/@extra-array/accumulate.min)
|
7 | [:scroll:](https://unpkg.com/@extra-array/accumulate/)
|
8 | [:newspaper:](https://nodef.github.io/extra-array/)
|
9 | [:blue_book:](https://github.com/nodef/extra-array/wiki/)
|
10 |
|
11 | > Similar: [map], [filter], [reject], [reduce], [accumulate].
|
12 |
|
13 | > This is part of package [extra-array].
|
14 |
|
15 | [extra-array]: https://www.npmjs.com/package/extra-array
|
16 |
|
17 | <br>
|
18 |
|
19 | ```javascript
|
20 | array.accumulate(x, fr, [acc]);
|
21 | // x: an array
|
22 | // fr: reduce function (acc, v, i, x)
|
23 | // acc: initial value
|
24 | ```
|
25 |
|
26 | ```javascript
|
27 | const array = require("extra-array");
|
28 |
|
29 | var x = [1, 2, 3, 4];
|
30 | array.accumulate(x, (acc, v) => acc+v);
|
31 | // [ 1, 3, 6, 10 ]
|
32 |
|
33 | array.accumulate(x, (acc, v) => acc+v, 100);
|
34 | // [ 101, 103, 106, 110 ]
|
35 | ```
|
36 |
|
37 | <br>
|
38 | <br>
|
39 |
|
40 |
|
41 | ## References
|
42 |
|
43 | - [Data.List.scanl: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:scanl)
|
44 | - [itertools.accumulate: Python](https://docs.python.org/3/library/itertools.html#itertools.accumulate)
|
45 |
|
46 | [accumulate]: https://github.com/nodef/extra-array/wiki/accumulate
|
47 | [map]: https://github.com/nodef/extra-array/wiki/map
|
48 | [filter]: https://github.com/nodef/extra-array/wiki/filter
|
49 | [reduce]: https://github.com/nodef/extra-array/wiki/reduce
|
50 | [reject]: https://github.com/nodef/extra-array/wiki/reject
|