• Groups the elements of an array based on the given function and returns the count of elements in each group

    Example

    countBy([6.1, 4.2, 6.3], Math.floor); // { 4: 1, 6: 2 }
    

    Example

    countBy(['one', 'two', 'three'], 'length'); // { 3: 2, 5: 1 }
    

    Type Parameters

    • Value

    Parameters

    • array: Value[]
    • fn: string | ((value: Value, index: number, array: Value[]) => any)

    Returns Record<string, number>

Generated using TypeDoc