Hi, I need to sort a list of strings "german-style...
# javascript
a
Hi, I need to sort a list of strings "german-style" in Kotlin/JS. This means, considering Umlauts and the letter "ß" (located between "s" and "t". Many SO-Comments recomend using java.text.Collator but I wonder if there is a js-way to do it since I cannot use the java imports due to project constraints. e.g.: listOf("Ä", "a", "A", "s", "ß", "?", "1", "2", "3") will be sorted as [1, 2, 3, ?, A, a, s, Ä, ß] but actually I need the following order [1, 2, 3, ?, A, a, Ä, s, ß]. In SQL, COLLATE utf8mb4_german2_ci would do the trick. Does anybody know how I could get the same result using kotlin/js?
n
Not sure if these two question solve your problem https://stackoverflow.com/questions/6909126/javascript-sort-with-unicode https://stackoverflow.com/questions/3630645/how-to-compare-unicode-strings-in-javascript Basically this is pure JS question I'd say, and most of them recommend either use
.localeCompare
if the locale is set to german, if not then a brute force sorting algo should be written. If anyone else can pitch in with a better answer
a
Hi @Nikola Milovic, thanks for your reply! I went for the brute force algorithm. But still, its hard to imagine that this problem isn't common enough to have a kotlin/JS solution, especially since the
.localeCompare
is not directly available in Kotlin/JS