Skip to content

Commit 9615e0a

Browse files
committed
docs(alphabetical): document sort stability
1 parent 9717654 commit 9615e0a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

docs/array/alphabetical.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ the property to use for sorting, return a new array with the objects
1111
sorted alphabetically. A third, and optional, argument allows you to
1212
sort in descending order instead of the default ascending order.
1313

14+
The function preserves the original order of items with equal values.
15+
1416
For numerical sorting, see the [sort](./sort) function.
1517

1618
```ts

tests/array/alphabetical.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ describe('alphabetical', () => {
2121
const result = _.alphabetical(cast(null), x => x)
2222
expect(result).toEqual([])
2323
})
24+
test('sort is stable', () => {
25+
const list = [{ id: 3, name: 'Leo' }, { id: 1, name: 'Leo' }, { id: 2, name: 'Leo' }]
26+
const result = _.alphabetical(list, i => i.name)
27+
expect(result).toEqual(list)
28+
});
2429
})

0 commit comments

Comments
 (0)