2026-05-31 13:54:31 +02:00

21 lines
525 B
JavaScript

const require_sum = require("./sum.js");
//#region src/math/mean.ts
/**
* Calculates the average of an array of numbers.
*
* If the array is empty, this function returns `NaN`.
*
* @param {number[]} nums - An array of numbers to calculate the average.
* @returns {number} The average of all the numbers in the array.
*
* @example
* const numbers = [1, 2, 3, 4, 5];
* const result = mean(numbers);
* // result will be 3
*/
function mean(nums) {
return require_sum.sum(nums) / nums.length;
}
//#endregion
exports.mean = mean;