As discussed in the comments, this looks like an inconsistency either in the spec or the vendor implementation.
Since an earlier question on the same topic didn't have any answers I'd be happy to go with, here's a manual implementation:
const input = ["aaaaa", "aaa", "aa", "aaaa", "aA", "Aa", "AA", "ab", "aB", "Ab", "AB"];
function caseSensitiveCompare(a, b) {
// Sort character by character, return early if possible
for (let ii = 0; ii < Math.max(a.length, b.length); ii++) {
const aChar = a.charAt(ii);
const bChar = b.charAt(ii);
// If inputs match up to here, but lengths don't match, sort by length
if (!(aChar && bChar)) {
return a.length - b.length;
}
// If we meet a differing character, return early
const comp = aChar.localeCompare(bChar);
if (comp !== 0) {
return comp;
}
}
// If we found nothing to do, the strings are equal
return 0;
}
console.log(input.sort(caseSensitiveCompare));