Created
December 4, 2015 11:22
-
-
Save thers/bfcb2ab36d65fcebbf25 to your computer and use it in GitHub Desktop.
Standard deviation func
This file contains 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
/** | |
* Calculates standrad deviation | |
* | |
* @param {Array} arr | |
* @returns {number} | |
*/ | |
function standradDeviation (arr) { | |
const n = arr.length; | |
const bias = Math.pow(arr.reduce((acc, v) => acc+v, 0)/n , 2); | |
const s2 = arr.reduce((acc,v) => acc+(v*v-bias), 0)/(n-1); | |
return Math.sqrt(s2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment