@extra-array/count-on
v2.6.72
Published
Counts occurrences of values.
Downloads
196
Readme
Counts occurrences of values. :running: :vhs: :package: :moon:
Alternatives: one, all. This is part of package extra-array.
array.countOn(x, [fn], [ths]);
// x: an array
// fn: map function (v, i, x)
// ths: this argument
// --> Map {value => count}
const array = require('extra-array');
var x = [1, 1, 2, 2, 4];
array.countOn(x);
// Map(3) { 1 => 2, 2 => 2, 4 => 1 }
var x = [1, 2, 3, 4];
array.countOn(x, v => v % 2);
// Map(2) { 1 => 2, 0 => 2 }