Page Contents

Home > @loopback/context > compareByOrder

compareByOrder() function

Compare two values by the predefined order


export declare function compareByOrder(a: string | symbol | undefined | null, b: string | symbol | undefined | null, order?: (string | symbol)[]): number;


Parameter Type Description
a string | symbol | undefined | null First value
b string | symbol | undefined | null Second value
order (string | symbol)[] (Optional) An array of values as the predefined order




The comparison is performed as follows:

  1. If both values are included in order, they are sorted by their indexes in order. 2. The value included in order comes after the value not included in order. 3. If neither values are included in order, they are sorted: - symbol values come before string values - alphabetical order for two symbols or two strings