Skip to content

countEach

Subhajit Sahu edited this page May 3, 2023 · 1 revision

Count occurrences of each distinct value.

Alternatives: count, countEach.
Similar: count, segregate.


function countEach(x, fm)
// x:  an array
// fm: map function (v, i, x)
const xarray = require('extra-array');

var x = [1, 1, 2, 2, 4];
xarray.countEach(x);
// → Map(3) { 1 => 2, 2 => 2, 4 => 1 }

var x = [1, 2, 3, 4];
xarray.countEach(x, v => v % 2);
// → Map(2) { 1 => 2, 0 => 2 }


References

Clone this wiki locally