Extract collator
parent
7a6562e44e
commit
7e950a12f5
3
index.js
3
index.js
|
@ -1,4 +1,6 @@
|
||||||
const sortby = (properties) => (a, b) => {
|
const sortby = (properties) => (a, b) => {
|
||||||
|
const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' })
|
||||||
|
|
||||||
// if items is {prop1:value1, prop2:value2}
|
// if items is {prop1:value1, prop2:value2}
|
||||||
// then sort(['prop1', 'desc', 'prop2'])
|
// then sort(['prop1', 'desc', 'prop2'])
|
||||||
// will sort by prop1 desc and prop2
|
// will sort by prop1 desc and prop2
|
||||||
|
@ -11,7 +13,6 @@ const sortby = (properties) => (a, b) => {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' })
|
|
||||||
const compare = collator.compare(a[property], b[property])
|
const compare = collator.compare(a[property], b[property])
|
||||||
if (compare < 0) return order
|
if (compare < 0) return order
|
||||||
if (compare > 0) return -order
|
if (compare > 0) return -order
|
||||||
|
|
Loading…
Reference in New Issue