Skip to main content
Module

x/statistics/src/mean.ts

Deno basic statistics module.
Latest
File
import { sum } from "./sum.ts";
/** * The mean, _also known as average_, * is the sum of all values over the number of values. * This is a [measure of central tendency](https://en.wikipedia.org/wiki/Central_tendency): * a method of finding a typical or central value of a set of numbers. * * This runs on `O(n)`, linear time in respect to the array * * @param {number[]} x sample of one or more data points * @throws {Error} if the the length of x is less than one * @returns {number} mean * @example * mean([0, 10]); // => 5 */export function mean(x: number[]): number { if (!x.length) { throw new Error("mean requires at least one data point"); }
return sum(x) / x.length;}