The sortedByDescending works a bit like sortedBy. Internally, both use the sortedWith function:
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedByDescending(crossinline selector: (T) -> R?): List<T> {
return sortedWith(compareByDescending(selector))
}
The following is the implementation of compareByDescending:
@kotlin.internal.InlineOnly
public inline fun <T> compareByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator<T> =
Comparator { a, b -> compareValuesBy(b, a, selector) }
Note that just the order of variables is reversed to produce the descending order.