Skip to content
Subhajit Sahu edited this page Dec 8, 2022 · 13 revisions

Reduce values to a single value.

Similar: map, reduce, filter, reject.


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

var x = {a: 1, b: 2, c: 3, d: 4};
object.reduce(x, (acc, v) => acc+v);
// → 10

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


References

Clone this wiki locally