Function count

  • Counts the number of occurrences of each value in an iterable.

    it.count('hello') == it.m.map([['h', 1], ['e', 1], ['l', 2], ['o', 1]])
    

    Use the second parameter to get the key used to count.

    const input = [{x: 'a'}, {x: 'b'}]
    it.count(input, obj => obj.x) == it.m.map([[true, 2], [false, 0]])

    Type Parameters

    • Iter extends AnyIt<unknown>
    • V extends unknown
    • T = V

    Parameters

    • iter: Iter

      The iterable to count the occurrences from.

    • Optional key: ValFunc<V, T>

      The function used to determine the group key. Defaults to the identity function.

    Returns AnyItResult<Iter, Map<T, number>>

    • A Map containing the count of each value.