arrMedian method

num arrMedian(
  1. List<num> numbers
)

In statistics and probability theory, a median is a value separating the higher half from the lower half of a data sample, a population or a probability distribution. For a data set, it may be thought of as "the middle" value.

👉 Source

Example

print(Statistical().arrMedian([0.1,9,0,8,12,-1]));
//output 4.05

Implementation

num arrMedian(List<num> numbers) {
  var middle = numbers.length ~/ 2;
  var isEven = numbers.length % 2 == 0;
  numbers.sort();
  return isEven
      ? (numbers[middle - 1] + numbers[middle]) / 2
      : numbers[middle];
}