average method
Returns the average of all elements in the collection.
Implementation
double average() {
var count = 0;
num sum = 0;
for (final current in this) {
sum += current;
count++;
}
if (count == 0) {
throw StateError('No elements in collection');
} else {
return sum / count;
}
}