Last active
May 5, 2017 20:46
-
-
Save CarlosMChica/58aa2008e05b000716b791cfcb3b5119 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mostPopularLetterWithCount :: String -> (Char, Int) | |
mostPopularLetterWithCount xs = | |
swap . maximum . fmap swap . Map.toList . Map.fromListWith (+) $ [(x, 1) | x <- xs, not . isSpace $ x] | |
mostPopularWordWithCount :: String -> (String, Int) | |
mostPopularWordWithCount xs = | |
swap . maximum . fmap swap . Map.toList . Map.fromListWith (+) $ [(x, 1) | x <- words xs] | |
4. What was the most popular letter for each message? | |
mostPopularLetter :: String -> Char | |
mostPopularLetter = fst. mostPopularLetterWithCount | |
mostPopularWord :: String -> String | |
mostPopularWord = fst . mostPopularWordWithCount | |
5. What was the most popular letter overall? What was the most | |
popular word? | |
coolestLtr :: [String] -> Char | |
coolestLtr = mostPopularLetter . concat | |
coolestWord :: [String] -> String | |
coolestWord = mostPopularWord . unwords |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment