Jump to content

Unique characters: Difference between revisions

→‎{{header|Haskell}}: Added a variant which folds all strings down to a hash of character frequencies
(→‎{{header|JavaScript}}: Added a variant which folds the strings to a hash of character frequencies)
(→‎{{header|Haskell}}: Added a variant which folds all strings down to a hash of character frequencies)
Line 572:
putStrLn $
uniques
[ "133252abcdeeffd",
"a6789798st",
"yxcdfgxcyz"
]</lang>
{{Out}}
<pre>156bgstz</pre>
 
 
Or folding the strings down to a hash of character frequencies:
<lang haskell>import qualified Data.Map.Strict as M
 
--------- UNIQUE CHARACTERS FROM A LIST OF STRINGS -------
uniqueChars :: [String] -> String
uniqueChars ks =
[ k
| (k, v) <-
M.assocs $
foldr
(flip (foldr (flip (M.insertWith (+)) 1)))
M.empty
ks,
1 == v
]
 
--------------------------- TEST -------------------------
main :: IO ()
main =
putStrLn $
uniqueChars
[ "133252abcdeeffd",
"a6789798st",
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.