Last active
August 29, 2015 14:09
-
-
Save srikumarks/0cab3f60fcb85038aab8 to your computer and use it in GitHub Desktop.
Standard deviation in js
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
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