Page Contents
Home > @loopback/context > compareByOrder
compareByOrder() function
Compare two values by the predefined order
Signature:
export declare function compareByOrder(a: string | symbol | undefined | null, b: string | symbol | undefined | null, order?: (string | symbol)[]): number;
Parameters
| 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 |
Returns:
number
Remarks
The comparison is performed as follows:
- If both values are included in
order, they are sorted by their indexes inorder. 2. The value included inordercomes after the value not included inorder. 3. If neither values are included inorder, they are sorted: - symbol values come before string values - alphabetical order for two symbols or two strings