Skip to content

countAs

Subhajit Sahu edited this page May 17, 2020 · 17 revisions

Counts occurrences of values. 🏃 📼 📦 🌔 📒

Alternatives: one, all.

iterable.countOn(x, [fn], [ths]);
// x:   an iterable
// fn:  map function (v, i, x)
// ths: this argument
// --> Map {value => count}
const iterable = require('extra-iterable');

var x = [1, 1, 2, 2, 4];
iterable.countAs(x);
// Map(3) { 1 => 2, 2 => 2, 4 => 1 }

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

references

Clone this wiki locally