javascript-collections-framework
    Preparing search index...

    Type Alias Comparator<T>

    Comparator: (a: T, b: T) => number

    A function that orders two values: negative when a comes first, positive when b comes first, zero when they are equal in this order. Only the sign is used.

    It is the shape Array.prototype.sort accepts.

    Type Parameters

    • T

    Type Declaration

      • (a: T, b: T): number
      • Parameters

        • a: T
        • b: T

        Returns number

    const byLength: Comparator<string> = (a, b) => a.length - b.length
    ['ccc', 'a', 'bb'].sort(byLength) // ['a', 'bb', 'ccc']