Skip to content

Instantly share code, notes, and snippets.

@a-s-o
Created April 25, 2015 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-s-o/dab6b96e93a8fa337dd1 to your computer and use it in GitHub Desktop.
Save a-s-o/dab6b96e93a8fa337dd1 to your computer and use it in GitHub Desktop.
Basic functions for stats
function sum (arr) {
return arr.reduce((x, i) => x + i, 0);
}
function mean (arr) {
return sum(arr) / arr.length;
}
function variance (arr) {
let m = mean(arr);
let total = arr.reduce((x, i) => Math.pow( i - m, 2 ), 0);
return total / arr.length;
}
function stdDev (arr) {
return Math.sqrt( variance(arr) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment