Given this example:
let a = ['New York', 'New Hampshire', 'Maryland'];
let collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
a.sort(collator.compare);
How might this array be sorted in descending order?
You can switch the parameters:
a.sort( (x, y) => collator.compare(y, x) )
or sort and reverse:
a.sort(collator.compare).reverse()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With