countBy (source code)
- Curried: true
- Failsafe status: alternative available
The countBy
function counts the number of items in an array that match the
provided pattern.
pattern
: The pattern using which objects will be matched.entityArray
: The array of objects from which the objects with the given pattern will be counted.
const array = [
{ name: "Oliver", age: 20 },
{ name: "Sam", age: 40 },
{ name: "George", age: 41 },
{ name: "Smith", age: 20 },
];
countBy({ age: 20 }, array); // returns 2
countBy({ age: gt(__, 40) }, array); // returns 1
countBy({ age: 50 }, array); // returns 0