count - nodef/extra-map GitHub Wiki

Count values which satisfy a test.

Alternatives: count, countAs.

function count(x, ft)
// x:  a map
// ft: test function (v, k, x)
const map = require('extra-map');

var x = new Map(['a', 1], ['b', 1], ['c', 2], ['d', 2], ['e', 4](/nodef/extra-map/wiki/'a',-1],-['b',-1],-['c',-2],-['d',-2],-['e',-4));
map.count(x, v => v % 2 === 1);
// → 2

map.count(x, v => v % 2 === 0);
// → 3

References