Sort using a custom comparator: Difference between revisions

Content added Content deleted
(Frink)
Line 1,771: Line 1,771:
[strings, sample, sorted, Here, some, are, be, to]
[strings, sample, sorted, Here, some, are, be, to]
</pre>
</pre>

Alternately, here is a surprisingly powerful version of the sorter above that can sort based on the alphabetization rules of a very wide number of human languages. The language for the lexicographic comparison can be specified to the <CODE>lexicalCompare</CODE> function as an ISO 639-1 two-letter language code, or can be even more specific. For example, the following sorts a list of words based on the alphabetization rules for Danish.
<lang frink>f = {|a,b,lang| lexicalCompare[a,b,lang] }

words = ["Ærø", "Aalborg", "Tårnby", "Vejen", "Thisted", "Stevns", "Sønderborg", "Eliasen"]
println[sort[words, f, "da"]]</lang>
{{out}}
<pre>
[Eliasen, Stevns, Sønderborg, Thisted, Tårnby, Vejen, Ærø, Aalborg]
</pre>

Note that under the lexicographic ordering rules for Danish, that order is correct, with names beginning with "Aa" alphabetized last.


=={{header|FunL}}==
=={{header|FunL}}==