Created
November 14, 2013 04:08
-
-
Save rishabhmhjn/7461192 to your computer and use it in GitHub Desktop.
Standard Deviation Calculator
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 calcStandardDeviation(arr) { | |
// var arr = [23, 37, 45, 49, 56, 63, 63, 70, 72, 82]; | |
var count = arr.length | |
var mean = arr.reduce(function(total, num) { | |
total += num; | |
return total; | |
}, 0) / count; | |
var variance = arr.reduce(function(total, num) { | |
var diff = num - mean; | |
total += diff * diff; | |
return total; | |
}, 0) / count; | |
var sd = Math.sqrt(variance); | |
return sd; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment