everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
16 lines (15 loc) • 670 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.coefficientOfVariation = void 0;
/**
* Calculates the coefficient of variation (standard deviation divided by mean) of an array of numbers.
* @author @dailker
* @param {number[]} numbers - The input array of numbers.
* @returns {number} The coefficient of variation.
*/
function coefficientOfVariation(numbers) {
const mean = numbers.reduce((a, b) => a + b, 0) / numbers.length;
const std = Math.sqrt(numbers.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / numbers.length);
return std / mean;
}
exports.coefficientOfVariation = coefficientOfVariation;