arithmeticMean method

double arithmeticMean()

Returns the arithmetic mean (or average) of this Iterable, or double.nan if the iterable is empty.

For details, see https://en.wikipedia.org/wiki/Arithmetic_mean.`

Example: [5, 2].arithmeticMean() returns 3.5.

Implementation

double arithmeticMean() {
  var count = 0, sum = 0.0;
  for (final value in this) {
    count++;
    sum += value;
  }
  return count == 0 ? double.nan : sum / count;
}