nthLargest<T> function

T? nthLargest<T>(
  1. Iterable<T> items,
  2. int k,
  3. Comparator<T> compare
)

Returns the k-th largest element (0-based: k = 0 is the maximum), or null if k is out of range. Equivalent to nthSmallest from the other end. Audited: 2026-06-12 11:26 EDT

Implementation

T? nthLargest<T>(Iterable<T> items, int k, Comparator<T> compare) =>
    nthSmallest(items, k, (T a, T b) => compare(b, a));