harmonicMean method
Returns the harmonic mean of this Iterable, or double.nan if the sum of the iterable is 0.
For details, see https://en.wikipedia.org/wiki/Harmonic_mean.average
Example: [2, 3].harmonicMean()
returns 2.4
.
Implementation
double harmonicMean() {
var count = 0, sum = 0.0;
for (final value in this) {
count++;
sum += 1 / value;
}
return sum == 0 ? double.nan : count / sum;
}