@jonahsnider/util

    Function frequencyTable

    • 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

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

      count to count the occurrences of one value in an iterable

      Iterable

    MMNEPVFCICPMFPCPTTAAATR