Intl.Collator descending order sort

javascript

Solution

You can switch the parameters:

a.sort( (x, y) => collator.compare(y, x) )

or sort and reverse:

a.sort(collator.compare).reverse()

Problem

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?

Original source