Sort by human number 1, ..., 9, 10 and not 1,10, 2
parent
a821e706cb
commit
3b0a56ba50
7
index.js
7
index.js
|
@ -11,8 +11,11 @@ const sortby = (properties) => (a, b) => {
|
|||
i++
|
||||
}
|
||||
|
||||
if (a[property] < b[property]) return order
|
||||
if (a[property] > b[property]) return -order
|
||||
const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' })
|
||||
const compare = collator.compare(a[property], b[property])
|
||||
if (compare > 0) return order
|
||||
if (compare < 0) return -order
|
||||
|
||||
}
|
||||
|
||||
return 0
|
||||
|
|
Loading…
Reference in New Issue