> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# sortWith

Sorts an array using multiple comparators in priority order.

The first comparator has highest priority. When it returns 0 (tie),
the next comparator is used, and so on.

```typescript
sortWith(users, [
  ascend(u => u.department),
  descend(u => u.age),
])
```

## Usage

### `sortWith<T>(array: readonly T[], comparators: ReadonlyArray<(a: T, b: T) => number>)`

Sorts an array using multiple comparators in priority order.

The first comparator has highest priority. When it returns 0 (tie),
the next comparator is used, and so on.

```typescript
import { sortWith } from 'massaman'
// or:  import { sortWith } from 'massaman/array'

sortWith(users, [
  ascend(u => u.department),
  descend(u => u.age),
])
```

#### Parameters


arrayreadonly T[]required

the source array.


comparatorsReadonlyArray<(a: T, b: T) => number>required

the comparators to apply in priority order.

#### Returns

a new array ordered by the supplied comparators. The input array is not mutated.

```typescript
T[]
```
