Sort the letters of string in alphabetical order: Difference between revisions
Content added Content deleted
m (→case insensitive: or for aaaAAAbBnnNN) |
m (→{{header|Haskell}}: Added a variant which constructs a sorted string from a map of character counts) |
||
Line 177: | Line 177: | ||
{{Out}} |
{{Out}} |
||
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre> |
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre> |
||
Or, just constructing a sorted string from the character counts: |
|||
<lang haskell>import qualified Data.Map.Strict as M |
|||
----------------- MAP OF CHARACTER COUNTS ---------------- |
|||
charCounts :: String -> M.Map Char Int |
|||
charCounts = |
|||
foldr (flip (M.insertWith (+)) 1) M.empty |
|||
--------------------------- TEST ------------------------- |
|||
main :: IO () |
|||
main = |
|||
print $ |
|||
M.toList |
|||
( charCounts |
|||
"Was the misspelling of alphabetical as alphabitical a joke ?" |
|||
) |
|||
>>= uncurry (flip replicate)</lang> |
|||
{{Out}} |
|||
<pre>" ?Waaaaaaaaabbcceeeefghhhiiiiijkllllllmnoopppssssttt"</pre> |
|||
=={{header|jq}}== |
=={{header|jq}}== |