Skip to content
Subhajit Sahu edited this page May 3, 2023 · 18 revisions

Reduce values of array to a single value.

Alternatives: reduce, reduceRight.
Similar: map, filter, reject, reduce.


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

var x = [1, 2, 3, 4];
xarray.reduce(x, (acc, v) => acc+v);
// → 10

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


References

Clone this wiki locally