median property
double
get
median
Returns the median of a List<num>. Returns 0 if empty.
Implementation
double get median {
if (isEmpty) return 0;
if (this is! List<num>) {
throw UnsupportedError('median is only supported on List<num>');
}
final sorted = List<num>.from(this as List<num>)..sort();
final mid = sorted.length ~/ 2;
return sorted.length.isOdd
? sorted[mid].toDouble()
: (sorted[mid - 1] + sorted[mid]) / 2;
}