Skip to content

Commit 9717654

Browse files
committed
docs(sort): document sort stability
1 parent 5fbee15 commit 9717654

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

docs/array/sort.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ since: 12.1.0
88

99
Given an array, return a new array sorted either by the numerical property specified in the get function or the numerical value of its items if no get function is passed. A third, and optional, argument allows you to sort in descending order instead of the default ascending order.
1010

11+
The function preserves the original order of items with equal values.
12+
1113
This function only supports numerical sorting. For alphabetic sorting, see the [alphabetical](./alphabetical) function.
1214

1315
```ts

tests/array/sort.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ describe('sort', () => {
2626
expect(result[1]).toBe(1)
2727
expect(result[2]).toBe(2)
2828
})
29+
test('sort is stable', () => {
30+
const list = [2, 0, 1, 3]
31+
const result = _.sort(list, () => 0)
32+
expect(result).toEqual(list)
33+
});
2934
})

0 commit comments

Comments
 (0)