Files
30-seconds-of-code/test/standardDeviation/standardDeviation.js
2018-01-09 06:09:49 -05:00

7 lines
276 B
JavaScript

module.exports = (arr, usePopulation = false) => {
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
return Math.sqrt(
arr.reduce((acc, val) => acc.concat((val - mean) ** 2), []).reduce((acc, val) => acc + val, 0) /
(arr.length - (usePopulation ? 0 : 1))
);
};