• Category

    Calculate the mode of an iterable. Strict equality (===) is used to compare elements.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      Values to use in the calculation

    Returns T[]

    An array of the modes of values

    Math

    Example

    const values = [1, 2, 2, 3, 3];

    mode(values); // [2, 3]

    See

    • (mean:1) to calculate the mean of an array
    • (median:1) to calculate the median of an array