I'm trying to sort Hungarian words in the dictionary by alphabetical order. The expected order for all letters should be aábcdeéfggyhiíjklmnoóöőpqrsttyuúüűvwxyz
I was trying to use Intl.Collator() and localeCompare but the expected output was never right.
for example:
console.log(["baj", 'betűz', 'ä', "bácsi"].sort(new Intl.Collator('hu').compare));
//expected output ["ä", "baj", "bácsi", "betűz"]
what I got is Array ["ä", "bácsi", "baj", "betűz"]
á comes before a but should be after a
and it happened for é and í also.
I was trying to use
.sort(function(a, b) {
let letterA = a.toUpperCase();
let letterB = b.toUpperCase();
if (letterA < letterB) {
return -1;
}
if (letterA > letterB) {
return 1;
}
return 0;
});
but words with specials signs were put at the end of the array which is not what I want.
Any suggestions on how can I resolve that issue?