Unique characters: Difference between revisions

Content added Content deleted
(→‎{{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: Line 572:
putStrLn $
putStrLn $
uniques
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",
[ "133252abcdeeffd",
"a6789798st",
"a6789798st",