Function variance

  • Category

    Calculate the variance of a sequence of numbers.

    Time complexity: O(n)

    Space complexity: O(1)

    Parameters

    • values: readonly number[]

      Values to use in the calculation

    • meanValue: number = ...

      The mean of values, will be calculated if not provided

    Returns number

    The variance of values

    Math

    Example

    variance([1, 2, 3]); // 1