Skip to content

mean

Calculates the arithmetic mean of an array of numbers.

Syntax

typescript
mean(values: number[]): number

Parameters

NameTypeDescription
valuesnumber[]Array of numbers.

Return

TypeDescription
numberArithmetic mean of the values, or 0 if empty.

Example

typescript
mean([1, 2, 3, 4]); // 2.5
mean([]); // 0

Notes

  • Throws TypeError if the argument is not an array of numbers.
  • Uses the add function to sum the values.

References

Released under the MIT License.