bstrees
    Preparing search index...

    Type Alias Comparator<T>

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

    Defines the sort order of a tree.

    Returns a negative number when a sorts before b, a positive number when a sorts after b and zero when they are equal. It must be a consistent total order (reflexive, antisymmetric and transitive) and must never return NaN. The tree may call it with its arguments in either order.

    It must not modify the tree it orders: a mutating method of that tree called from the comparator throws a TypeError and leaves the tree unchanged. Reading the tree or modifying other trees is allowed, but searches of that tree (has, get, floor, range, ...) and its iterators resuming after a change call the comparator again, so they need a guard against infinite recursion.

    Type Parameters

    • T

    Type Declaration

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

        • a: T
        • b: T

        Returns number

    const byPrice: Comparator<{ price: number }> = (a, b) => a.price - b.price;