Interface Comparable<T>

Interface representing a comparable object that can be compared to another object of the same type.

Comparable

Since

version 1.4.0

Author

Manuel Santos ney.br.santos@gmail.com

interface Comparable<T> {
    compareTo(other): number;
}

Type Parameters

  • T

    The type of objects being compared.

Methods

Methods

  • Compares this object to another object of the same type.

    Parameters

    • other: T

      The object to compare with.

    Returns number

    A negative number if this object is less than the other, zero if they are equal, or a positive number if this object is greater than the other.

    Example

    (1).compareTo(2);
    "a".compareTo("b");
    true.compareTo(false);

    Example

    const string1 = "apple";
    const string2 = "banana";
    const stringComparison = string1.compareTo(string2);
    console.log(stringComparison); // Output: -1 (Example output; actual output will vary)

    Example

    const number1 = 10;
    const number2 = 5;
    const numberComparison = number1.compareTo(number2);
    console.log(numberComparison); // Output: 1 (Example output; actual output will vary)

    Example

    const date1 = new Date("2023-01-01");
    const date2 = new Date("2023-01-15");
    const dateComparison = date1.compareTo(date2);
    console.log(dateComparison); // Output: -1 (Example output; actual output will vary)

Generated using TypeDoc