interQuartileRange function

  1. @visibleForTesting
num interQuartileRange(
  1. List<num> sample
)

The inter-quartile range of a non-empty sample. The quartiles are the medians of the lower and upper half, where an odd sample has its median in both.

Implementation

@visibleForTesting
num interQuartileRange(List<num> sample) {
  final sorted = [...sample]..sort();
  final half = (sorted.length + 1) ~/ 2;
  num quartile(int i) => half.isEven ? (sorted[i - 1] + sorted[i]) / 2 : sorted[i];
  return quartile(sorted.length ~/ 2 + half ~/ 2) - quartile(half ~/ 2);
}