median
Calculates the median of an array of numbers.
Syntax
typescript
median(arr: number[]): numberParameters
| Name | Type | Description |
|---|---|---|
arr | number[] | Array of numbers. |
Return
| Type | Description |
|---|---|
number | Median of the values. |
Example
typescript
median([1, 2, 3, 4, 5]); // 3
median([1, 2, 3, 4]); // 2.5Notes
- Throws
TypeErrorif the argument is not an array of numbers. - Returns
NaNif the array is empty.
