@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
103 lines (51 loc) • 1.86 kB
Markdown
---
lang: en
title: 'API docs: context.comparebyorder'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context
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
**Signature:**
```typescript
export declare function compareByOrder(a: string | symbol | undefined | null, b: string | symbol | undefined | null, order?: (string | symbol)[]): number;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
a
</td><td markdown="1">
string \| symbol \| undefined \| null
</td><td markdown="1">
First value
</td></tr>
<tr><td markdown="1">
b
</td><td markdown="1">
string \| symbol \| undefined \| null
</td><td markdown="1">
Second value
</td></tr>
<tr><td markdown="1">
order
</td><td markdown="1">
(string \| symbol)\[\]
</td><td markdown="1">
_(Optional)_ An array of values as the predefined order
</td></tr>
</tbody></table>
**Returns:**
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