median function Null safety

double median(
  1. Array a
)

Return the median of a array

Examples

var n = Array([1, 2, 3]);

print(median(n));

/* output:
2.0
*/

Implementation

double median(Array a) {
  var middle = a.length ~/ 2;
  if (a.length % 2 == 1) {
    return a[middle];
  } else {
    return (a[middle - 1] + a[middle]) / 2.0;
  }
}