averageBy method

double? averageBy(
  1. num selector(
    1. T
    )
)

Returns the average value (arithmetic mean) of all values produces by the selector function that is applied to each element.

Example:

[1, 2, 3].averageBy((n) => n);               // 2.0
['cat', 'horse'].averageBy((s) => s.length); // 4.0

Implementation

double? averageBy(num Function(T) selector) {
  ArgumentError.checkNotNull(selector, 'selector');
  if (isEmpty) return null;
  return sumByDouble(selector) / length;
}