Compares two values that implement the Comparable interface,
by invoking the compareTo method on the first value,
with the second value as the argument.
Example
classPersonimplementsComparable<Person> { constructor(publicreadonlyname: string, publicreadonlyage: number) { } compareTo(other: Person): number { // implement this any way you want returnnaturalOrder(this.age, other.age); } } [newPerson('a', 100), newPerson('b', 20), newPerson('c', 50)].sort(comparables);
Compares two values that implement the
Comparable
interface, by invoking thecompareTo
method on the first value, with the second value as the argument.Example