Use exponent ** operator over Math.pow

This commit is contained in:
atomiks
2018-01-01 04:40:03 +11:00
parent 7edaae36a1
commit acbb3903fa
2 changed files with 2 additions and 4 deletions

View File

@ -10,9 +10,7 @@ You can omit the second argument to get the sample standard deviation or set it
const standardDeviation = (arr, usePopulation = false) => {
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
return Math.sqrt(
arr
.reduce((acc, val) => acc.concat(Math.pow(val - mean, 2)), [])
.reduce((acc, val) => acc + val, 0) /
arr.reduce((acc, val) => acc.concat((val - mean) ** 2), []).reduce((acc, val) => acc + val, 0) /
(arr.length - (usePopulation ? 0 : 1))
);
};