mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 03:34:26 +03:00
28 lines
452 B
Markdown
28 lines
452 B
Markdown
|
# mean
|
||
|
|
||
|
Calculates the average of an array of numbers.
|
||
|
|
||
|
If the array is empty, this function returns `NaN`.
|
||
|
|
||
|
## Signature
|
||
|
|
||
|
```typescript
|
||
|
function mean(nums: number[]): number;
|
||
|
```
|
||
|
|
||
|
### Parameters
|
||
|
|
||
|
- `nums` (`number[]`): An array of numbers to calculate the average.
|
||
|
|
||
|
### Returns
|
||
|
|
||
|
(`number`): The average of all the numbers in the array.
|
||
|
|
||
|
## Examples
|
||
|
|
||
|
```typescript
|
||
|
const numbers = [1, 2, 3, 4, 5];
|
||
|
const result = mean(numbers);
|
||
|
// result will be 3
|
||
|
```
|