Skip to content

Instantly share code, notes, and snippets.

@srikumarks
Last active August 29, 2015 14:09
Show Gist options
  • Save srikumarks/0cab3f60fcb85038aab8 to your computer and use it in GitHub Desktop.
Save srikumarks/0cab3f60fcb85038aab8 to your computer and use it in GitHub Desktop.
Standard deviation in js
function stddev(values) {
return Math.sqrt(mean(values.map(square)) - square(mean(values)));
}
function mean(values) {
return values.reduce(add, 0) / values.length;
}
function add(x, y) {
return x + y;
}
function square(x) {
return x * x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment