Calculates the sample variance of a specified numeric property in an array of objects. Uses the formula: variance = Σ((x - mean)²) / (n - 1)
The type of objects in the array.
The array of objects.
The key whose numeric values will be used.
The sample variance, or NaN if fewer than 2 valid numbers exist.
const data = [{ a: 2 }, { a: 4 }, { a: 4 }, { a: 4 }, { a: 5 }, { a: 5 }, { a: 7 }, { a: 9 }];varianceBy(data, 'a'); // Returns 4 Copy
const data = [{ a: 2 }, { a: 4 }, { a: 4 }, { a: 4 }, { a: 5 }, { a: 5 }, { a: 7 }, { a: 9 }];varianceBy(data, 'a'); // Returns 4
Calculates the sample variance of a specified numeric property in an array of objects. Uses the formula: variance = Σ((x - mean)²) / (n - 1)