Skip to content

Instantly share code, notes, and snippets.

@thers
Created December 4, 2015 11:22
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 thers/bfcb2ab36d65fcebbf25 to your computer and use it in GitHub Desktop.
Save thers/bfcb2ab36d65fcebbf25 to your computer and use it in GitHub Desktop.
Standard deviation func
/**
* 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