minOf<T extends Comparable<T>> function

T minOf<T extends Comparable<T>>(
  1. T a, {
  2. required Array<T> others,
  3. Comparator<T>? comparator,
})

Returns the smaller of the given values according to the order specified by the given comparator.

Implementation

T minOf<T extends Comparable<T>>(
  T a, {
  required Array<T> others,
  Comparator<T>? comparator,
}) {
  if (others.isEmpty) return a;
  var min = a;
  for (final other in others) {
    if (comparator == null) {
      if (min < other) {
        min = other;
      }
    } else {
      if (other > min) {
        min = other;
      }
    }
  }
  return min;
}