JS natural/numerical sort example.

PHOTO EMBED

Mon Feb 08 2021 07:01:14 GMT+0000 (Coordinated Universal Time)

Saved by @saisandeepvaddi #javascript

const collator = new Intl.Collator(undefined, {
    usage: 'sort',
    numeric: true
})

const simple = ['a1', 'a12', 'a2']
simple.sort(collator.compare)
// => ['a1', 'a2', 'a12']

const objects = [{"id": "a1"}, {"id": "a12"}, {"id": "a2"}]
const by = (key) => (a, b) => collator.compare(a[key], b[key])
objects.sort(by('id'))
// => [{id: 'a1'}, {id: 'a2'}, {id: 'a12'}]
content_copyCOPY

https://gist.github.com/saisandeepvaddi/1b619bc6c72fe7a9e11dcbe26917d864