Use explicit default value
This commit is contained in:
@ -6,7 +6,7 @@ of the values to determine the standard deviation of an array of numbers.
|
||||
Since there are two types of standard deviation, population and sample, you can use a flag to switch to population (sample is default).
|
||||
|
||||
```js
|
||||
const standardDeviation = (arr, usePopulation) => {
|
||||
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)), [])
|
||||
|
||||
Reference in New Issue
Block a user