We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0e781ba commit 24445c0Copy full SHA for 24445c0
src/sorter.js
@@ -0,0 +1,3 @@
1
+export const sort = (list = [], key = '') => list.sort(compare(key))
2
+
3
+const compare = key => (a, b) => a[key].localeCompare(b[key])
test/sorter.spec.js
@@ -0,0 +1,20 @@
+import { sort } from '../src/sorter'
+import { expect } from 'chai'
4
+describe('sort', () => {
5
6
+ const data = [{
7
+ name: "Foo"
8
+ }, {
9
+ name: "Bar"
10
11
+ name: "Zab"
12
+ }]
13
14
+ it('should sort string property', () => {
15
+ const sorted = sort(data, 'name')
16
+ expect(sorted[0].name).to.eq('Bar')
17
+ expect(sorted[1].name).to.eq('Foo')
18
+ expect(sorted[2].name).to.eq('Zab')
19
+ })
20
+})
0 commit comments