Function comparables

  • 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

    class Person implements Comparable<Person> {
    constructor(public readonly name: string, public readonly age: number) {
    }
    compareTo(other: Person): number {
    // implement this any way you want
    return naturalOrder(this.age, other.age);
    }
    }
    [new Person('a', 100), new Person('b', 20), new Person('c', 50)].sort(comparables);

    Type Parameters

    Type Parameters

    • T

    Parameters

    Returns number

Generated using TypeDoc