Extract collator

master
Frédéric Matte 2023-09-28 22:53:58 -04:00
parent 7a6562e44e
commit 7e950a12f5
1 changed files with 2 additions and 1 deletions

View File

@ -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