GuobaGuoba Utils

counting

@guoba-ai/utils / array / counting

Function: counting()

function counting<T>(array, fn): Record<string, number>;

Defined in: array.ts:256

Count occurrences of each key derived from array items.

Type Parameters

T

T

Parameters

array

T[]

The array to count

fn

(item) => string

Function that returns a key for each item

Returns

Record<string, number>

An object mapping keys to their occurrence count

Example

counting(['a', 'b', 'a', 'c', 'b', 'a'], v => v)
// { a: 3, b: 2, c: 1 }

On this page