-
Notifications
You must be signed in to change notification settings - Fork 1
reduce
Subhajit Sahu edited this page May 9, 2020
·
24 revisions
Reduces values to a single value. [:running:] [:vhs:] [:package:] [:moon:]
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.reduce(x, (acc, v) => acc+v)];
// 10
[...iterable.reduce(x, (acc, v) => acc+v, 100)];
// 110
- Array.prototype.reduce(): MDN web docs
- iterable_reduce: PHP
- Data.List.reduce(): Haskell [:running:]: https://npm.runkit.com/@extra-iterable/reduce [:vhs:]: https://asciinema.org/a/vAxGu2mHltEZaHzzWTpCExH1p [:package:]: https://www.npmjs.com/package/@extra-iterable/reduce [:moon:]: https://www.npmjs.com/package/@extra-iterable/reduce.min