@loopback/docs
Version:
Documentation for LoopBack 4
42 lines (26 loc) • 1.45 kB
Markdown
---
lang: en
title: 'API docs: context.comparebyorder'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.context.comparebyorder.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/context](./context.md) > [compareByOrder](./context.comparebyorder.md)
## compareByOrder() function
Compare two values by the predefined order
<b>Signature:</b>
```typescript
export declare function compareByOrder(a: string | symbol | undefined | null, b: string | symbol | undefined | null, order?: (string | symbol)[]): number;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| a | <code>string | symbol | undefined | null</code> | First value |
| b | <code>string | symbol | undefined | null</code> | Second value |
| order | <code>(string | symbol)[]</code> | An array of values as the predefined order |
<b>Returns:</b>
`number`
## Remarks
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