Skip to main content
Module

x/statistics/src/add_to_mean.ts

Deno basic statistics module.
Latest
File
/** * When adding a new value to a list, one does not have to necessary * recompute the mean of the list in linear time. They can instead use * this function to compute the new mean by providing the current mean, * the number of elements in the list that produced it and the new * value to add. * * @param {number} mean current mean * @param {number} n number of items in the list * @param {number} newValue the added value * @returns {number} the new mean * * @example * addToMean(14, 5, 53); // => 20.5 */export function addToMean(mean: number, n: number, newValue: number): number { return mean + (newValue - mean) / (n + 1);}