给出以下示例:
let a = ['New York', 'New Hampshire', 'Maryland'];
let collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
a.sort(collator.compare);
该数组如何按降序排序?
最佳答案
您可以切换参数:
a.sort( (x, y) => collator.compare(y, x) )
或排序并反转:a.sort(collator.compare).reverse()