Skip to content

countAs

Subhajit Sahu edited this page Dec 2, 2022 · 17 revisions

Count occurrences of values.

Alternatives: count, countAs.


function countAs(x, fm)
// x:  a set
// fm: map function (v, v, x)
const set = require('extra-set');

var x = new Set([1, 2, 3, 4, 5]);
set.countAs(x, v => v % 3);
// → Map(3) { 1 => 2, 2 => 2, 0 => 1 }

set.countAs(x, v => v % 2);
// → Map(2) { 1 => 3, 0 => 2 }


References

Clone this wiki locally