variance
Calculates the sample variance of an array of numbers.
Syntax
typescript
variance(numbers: number[]): numberParameters
| Name | Type | Description |
|---|---|---|
numbers | number[] | Array of numbers to calculate variance. |
Return
| Type | Description |
|---|---|
number | The sample variance of the values. |
Example
typescript
variance([2, 4, 4, 4, 5, 5, 7, 9]); // 4
variance([1, 2, 3, 4, 5]); // 2.5Notes
- Throws
TypeErrorif the argument is not an array of numbers. - Returns
NaNfor an empty array. - Uses the sample variance formula.
