@technobuddha/library
Version:
A large library of useful functions
16 lines (14 loc) • 430 B
text/typescript
import { sum } from './sum.ts';
/**
* Calculates the Operations mean (average) of an array of numbers.
* @param numbers - An array of numbers to calculate the mean of.
* @returns The mean of the numbers, or `NaN` if the array is empty.
* @group Math
* @category Statistics
*/
export function mean(numbers: number[]): number {
if (numbers.length > 0) {
return sum(numbers) / numbers.length;
}
return Number.NaN;
}