I am trying to sort with two fields, say first name then last name. How do I chain Intl.Collator().compare so I don't have to do something silly like
const collator = new Intl.Collator()
const sorted = [...unsorted].sort( (a,b) => {
const c0 = collator.compare(a.firstName, b.firstName)
if (c0 === 0) {
return collator.compare(a.lastName, b.lastName)
}
else {
return c0;
}
}
I am basically looking for an equivalent of Java's Comparator.thenComparing()
This is specifically strings and specifically the Intl.Collate()
to handle accents so the techniques in Javascript sort array by two fields do not work well or equivalent to the implementation above.