Created
April 25, 2015 00:56
-
-
Save a-s-o/dab6b96e93a8fa337dd1 to your computer and use it in GitHub Desktop.
Basic functions for stats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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