Interface InlineComparator<T>

Interface representing a comparator function that can be used to compare two objects.

Comparator

Since

version 1.4.0

Author

Manuel Santos ney.br.santos@gmail.com

interface InlineComparator<T> ((a, b) => number)

Type Parameters

  • T

    The type of objects being compared.

  • Compares two objects of the same type.

    Parameters

    • a: T

      The first object to compare.

    • b: T

      The second object to compare.

    Returns number

    A negative number if a is less than b, zero if they are equal, or a positive number if a is greater than b.

    Example

    const stringComparator: InlineComparator<string> = (a, b) => a.localeCompare(b);
    const stringComparison = stringComparator("apple", "banana");
    console.log(stringComparison); // Output: -1 (Example output; actual output will vary)

    Example

    const numberComparator: InlineComparator<number> = (a, b) => a - b;
    const numberComparison = numberComparator(10, 5);
    console.log(numberComparison); // Output: 5 (Example output; actual output will vary)

    Example

    const dateComparator: InlineComparator<Date> = (a, b) => a.getTime() - b.getTime();
    const dateComparison = dateComparator(new Date("2023-01-01"), new Date("2023-01-15"));
    console.log(dateComparison); // Output: -1209600000 (Example output; actual output will vary)

Generated using TypeDoc