Skip to content

Instantly share code, notes, and snippets.

@coodoo
Last active January 8, 2018 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coodoo/372c34e936740104aaa3d2456d264158 to your computer and use it in GitHub Desktop.
Save coodoo/372c34e936740104aaa3d2456d264158 to your computer and use it in GitHub Desktop.
Find first not repeated char in a string. "Technical question" -> h. "Backend" -> b
-- f (x:xs) = case x `elem` xs of
-- True -> f xs
-- False -> x
f s = f' $ map toLower s
where
f' (x:xs) =
case x `elem` xs of
True -> f' xs
False -> x
f s = f' $ map toLower s
where f' (x:xs) = case x `elem` xs of True -> f' xs; False -> x
-- one liner version using if/else/then
f s = f' $ map toLower s where f' (x:xs) = if x `elem` xs then f' xs else x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment