Function comparatorForOrder

  • Creates a new Comparator that imposes the ordering defined by the given array. If the produced comparator receives a value, that isn't in the original array, an error will be thrown.

    Example

    const myComparator = comparatorForOrder(['b', 'a', 'c']);
    ['a', 'b', 'c', 'b'].sort(myComparator) == ['b', 'b', 'a', 'c'];

    Type Parameters

    Type Parameters

    • T

    Parameters

    • values: T[]

      the unique values in desired order

    Returns Comparator<T>

Generated using TypeDoc