reversed method
Returns a comparator that imposes the reverse ordering of this comparator.
The returned comparator evaluates compare(b, a)
instead of compare(a, b)
.
Example
final ascending = Comparator.naturalOrder<int>();
final descending = ascending.reversed();
final list = [1, 2, 3];
list.sort(descending.compare);
print(list); // [3, 2, 1]
Implementation
Comparator<T> reversed() => _ReversedComparator(this);