Function harmonicMean

  • Category

    Get the harmonic mean of an array of numbers.

    Time complexity: O(n)

    Space complexity: O(1)

    Parameters

    • array: readonly number[]

      The array to calculate the mean of

    Returns number

    The geometric mean of the array

    Math

    Example

    const array = [1, 4, 4];

    harmonicMean(array); // 2

    See

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