UNPKG

@sgratzl/science

Version:

Scientific and statistical computing in JavaScript.

10 lines (9 loc) 201 B
// Welford's algorithm. export default function mean(x) { var n = x.length; if (n === 0) return NaN; var m = 0, i = -1; while (++i < n) m += (x[i] - m) / (i + 1); return m; };