effect-io-ai

Package: effect
Module: Array

Array.countBy

Counts all the element of the given array that pass the given predicate

Example

import { Array } from "effect"

const result = Array.countBy([1, 2, 3, 4, 5], n => n % 2 === 0)
console.log(result) // 2

Signature

declare const countBy: { <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => number; <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): number; }

Source

Since v3.16.0