Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Standard deviation of set of values
/**
* Returns standard deviation of set of values.
*
* @param {number[]} values - Array of values.
* @returns {number} Standard devation of values.
*/
function stdDeviation(values) {
const avgOfValues = average(values);
const squaresOfDiffs = values.map(value => (value-avgOfValues)**2);
const avgOfSquaresOfDiffs = average(squaresOfDiffs);
return Math.sqrt(avgOfSquaresOfDiffs);
function average(values) {
return values.reduce((sum, value) => sum + value, 0) / values.length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.