Skip to content
Subhajit Sahu edited this page Dec 5, 2022 · 16 revisions

Reduce values of set to a single value.

Similar: map, reduce, filter, filterAt, reject, rejectAt.


function reduce(x, fr, acc?)
// x:   a map
// fr:  reduce function (acc, v, k, x)
// acc: initial value
const map = require('extra-map');

var x = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4]]);
map.reduce(x, (acc, v) => acc+v);
// → 10

map.reduce(x, (acc, v) => acc+v, 100);
// → 110


References

Clone this wiki locally