mediumBy<T> function

num mediumBy<T>(
  1. Iterable<T> list,
  2. num call(
    1. T
    )
)

Implementation

num mediumBy<T>(Iterable<T> list, num Function(T) call) {
  List<num> nl = [];
  for (var element in list) {
    nl.add(call(element));
  }
  nl.sort();
  int index = nl.length ~/ 2;
  if (nl.length % 2 == 0) {
    return (nl[index] + nl[index + 1]) / 2;
  } else {
    return nl[index];
  }
}