Computes the arithmetic mean of the numeric values produced for each element in the sequence.
The source iterable.
The arithmetic mean of the selected values.
Thrown when source is empty.
source
Provide a selector when the elements are not already numeric. All values are enumerated exactly once.
const numbers = [1, 2, 3, 4, 5];const avg = average(numbers);console.log(avg); // 3const people = [ { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Charlie', age: 35 },];const avgAge = average(people, p => p.age);console.log(avgAge); // 30 Copy
const numbers = [1, 2, 3, 4, 5];const avg = average(numbers);console.log(avg); // 3const people = [ { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Charlie', age: 35 },];const avgAge = average(people, p => p.age);console.log(avgAge); // 30
Type of elements within the source iterable.
Optional projection that extracts the numeric value for each element. Defaults to the element itself.
Computes the arithmetic mean of the numeric values produced for each element in the sequence.