Skip to content

accumulate

Subhajit Sahu edited this page May 13, 2020 · 15 revisions

Reduces values to a single value. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:]

iterable.reduce(x, fn, [acc]);
// x:   an iterable
// fn:  reduce function (acc, v, i, x)
// acc: initial value
const iterable = require('extra-iterable');

var x = [1, 2, 3, 4];
[...iterable.accumulate(x, (acc, v) => acc+v)];
// [ 1, 3, 6, 10 ]

[...iterable.accumulate(x, (acc, v) => acc+v, 100)];
// [ 101, 103, 106, 110 ]

references

Clone this wiki locally