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

m
add another version
(→‎{{header|Lua}}: added Lua concise version)
m (add another version)
Line 656:
Unsorted -> Now is the time for all good men to come to the aid of their country.
Sorted -> .aaccddeeeeeeffghhhiiiillmmmNnnooooooooorrrstttttttuwy
</pre>
 
=== alphabet-only counting version ===
<lang julia>
const alphabets = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
 
function lettercountingsort(s)
sorted = Char[]
for l in alphabets
append!(sorted, fill(l, count(==(l), s)))
end
return String(sorted)
end
 
println(lettercountingsort("Now is the time for all good men to come to the aid of their country."))
</lang>
<pre>
aaccddeeeeeeffghhhiiiillmmmNnnooooooooorrrstttttttuwy
</pre>
 
4,105

edits