@mirei/ts-collections
    Preparing search index...

    Function standardDeviation

    • Calculates the standard deviation of the numeric values produced by source.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable to inspect.

      • Optionalselector: Selector<TElement, number>

        Optional projection that extracts the numeric value for each element. Defaults to the element itself.

      • Optionalsample: boolean

        When true, computes the sample standard deviation; when false, computes the population standard deviation. Defaults to true.

      Returns number

      The calculated standard deviation, or NaN when there are insufficient values to compute it.

      Re-throws any error thrown while iterating source or executing selector.

      This function delegates to variance; when the variance is NaN, that value is returned unchanged. The iterable is enumerated exactly once using a numerically stable single-pass algorithm.

      const populationStdDev = standardDeviation([1, 2, 3, 4, 5], x => x, false);
      console.log(populationStdDev); // Math.sqrt(2)