Anonymous user
Sort the letters of string in alphabetical order: Difference between revisions
Sort the letters of string in alphabetical order (view source)
Revision as of 14:55, 15 August 2022
, 1 year ago→{{header|Lua}}: added Lua solution
(insert →Pascal: , allegedly add new external links [spam detection false positive]) |
(→{{header|Lua}}: added Lua solution) |
||
Line 657:
Sorted -> .aaccddeeeeeeffghhhiiiillmmmNnnooooooooorrrstttttttuwy
</pre>
=={{header|Lua}}==
Not idiomatic, ASCII assumed..
<lang lua>function sorted(s)
local b, c = {}, ""
s:gsub("(.)", function(c) local a=string.byte(c) b[a]=(b[a] or 0)+1 end)
for i = 0, 255 do if b[i] then c=c..string.rep(string.char(i),b[i]) end end
return c
end
print(sorted("Now is the time for all good men to come to the aid of their country."))</lang>
{{out}}
<pre> .Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
|