2

I'm trying to make a sorting system. The problem I am facing is that the 'aa' comes last because in Danish 'aa' means 'å' and that is why it is last. If it is possible I want the 'aa' to be first and not last in the list.

So to simplify, this is the output it gives me:

data
æ
ø
å
aa

...and the order I want is:

aa
data
æ
ø
å

Here is the code I am working on

var list = ["data", "aa", "å", "æ", "ø"];
const collator = new Intl.Collator("da", { caseFirst: "lower" });

document.write(list.sort(collator.compare));

EDIT: By switching to Icelandic instead of Danish, it seems to work on phones but not on computers.

EDIT2: On computers, it seems like Google Chrome and Microsoft Edge (Chromium) is not currently working, however Microsoft Edge (EdgeHTML), Mozilla Firefox and Safari are working. Internet Explorer just gets weird.

var list = ["data", "aa", "å", "æ", "ø"];
const collator = new Intl.Collator("is", { caseFirst: "lower" });

document.write(list.sort(collator.compare));

1 Answers1

-1

To do what you're looking for, I believe you will need to implement a custom sorter:

list = [ 'data', 'æ', 'ø', 'å', 'aa' ]
desiredOrder = [ 'aa', 'data', 'æ', 'ø', 'å' ]

sorter = (e1, e2) => {

    if(desiredOrder.indexOf(e1) < desiredOrder.indexOf(e2)){
        return -1
    }
    if(desiredOrder.indexOf(e1) > desiredOrder.indexOf(e2)){
        return 1
    }

    return 0

}

console.log(list.sort(sorter))
Greg
  • 1,845
  • 2
  • 16
  • 26