maxOf<T extends Comparable<T>> function

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

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

Implementation

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