Function frequencyTable

  • Category

    Construct a frequency table from an iterable. Similar to Python's Counter class.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      The iterable to construct a frequency table for

    Returns Map<T, number>

    A frequency table represented as a Map where keys are the elements and values are the frequency

    Example

    frequencyTable([1, 2, 2, 3, 3, 3]) // Map(3) { 1 => 1, 2 => 2, 3 => 3 };
    

    See

    count to count the occurrences of one value in an iterable

    Iterable