javascript-collections-framework
    Preparing search index...

    Interface Comparable<T>

    An object that states its own natural order through the compareSymbol protocol.

    a[compareSymbol](b) returns a negative number when a comes first, a positive number when b comes first, and zero when they are equal in the order. Natural order uses it only when both values implement it, and only its sign. Keep the order consistent: if a is before b, then b is after a, and if a is before b and b before c, then a is before c.

    class Version implements Comparable<Version> {
    constructor(readonly major: number, readonly minor: number) {}
    [compareSymbol](other: Version): number {
    return this.major - other.major || this.minor - other.minor
    }
    }
    [new Version(2, 0), new Version(1, 4)].sort(naturalOrder()) // 1.4, then 2.0
    interface Comparable<T> {
        "[compareSymbol]"(other: T): number;
    }

    Type Parameters

    • T
    Index
    • Parameters

      • other: T

      Returns number