mean
Calculates the arithmetic mean of an array of numbers.
Syntax
typescript
mean(values: number[]): numberParameters
| Name | Type | Description |
|---|---|---|
values | number[] | Array of numbers. |
Return
| Type | Description |
|---|---|
number | Arithmetic mean of the values, or 0 if empty. |
Example
typescript
mean([1, 2, 3, 4]); // 2.5
mean([]); // 0Notes
- Throws
TypeErrorif the argument is not an array of numbers. - Uses the
addfunction to sum the values.
