And to add onto that, strings.sort((a, b) => a.localeCompare(b))
is equivalent to strings.sort(new Intl.Collator().compare)
, just slightly less efficient.
Case-insensitive comparisons can't really be done in a language-independent manner, and my String.compare
is just lexicographic and based on character code order. It's not actually useful for language in general, and as .sort
does that by default, it's not useful there. However, it's useful for things like binary search of a sorted list of strings or other similar low-level locale-independent string tasks.