Sort the letters of string in alphabetical order: Difference between revisions

Realize in F#
m (→‎case insensitive: even neater)
(Realize in F#)
Line 81:
</pre>
 
=={{header|F_Sharp|F#}}==
<lang fsharp>
// Alphabetic sort. Nigel Galloway: July 27th., 2021
let n=['a';'A';'b';'B';'c';'C';'d';'D';'e';'E';'f';'F';'g';'G';'h';'H';'i';'I';'j';'J';'k';'K';'l';'L';'m';'M';'n';'N';'o';'O';'p';'P';'q';'Q';'r';'R';'s';'S';'t';'T';'u';'U';'v';'V';'w';'W';'x';'X';'y';'Y';'z';'Z']
let fG n g=let g=g|>Seq.countBy id|>Map.ofSeq in [for n in n->if Map.containsKey n g then [|for g in 1..g.[n]->n|]|>System.String else ""]|>String.concat ""
printfn "%s" (fG n "baNAnaBAnaNA")
</lang>
{{out}}
<pre>
aaaAAAbBnnNN
</pre>
=={{header|Go}}==
As in the case of the Wren entry, we write a function to bubble sort the characters of a string since this method is not, of course, used in Go's standard 'sort' package.
2,172

edits