RosettaCodeData/Task/Averages-Mode/Haskell/averages-mode-2.hs
Ingy döt Net 0457928c3e ...
2013-04-10 15:42:53 -07:00

6 lines
223 B
Haskell

import Data.List (group, sort)
mode :: (Ord a) => [a] -> [a]
mode xs = map fst $ filter ((==best).snd) counts
where counts = map (\l -> (head l, length l)) . group . sort $ xs
best = maximum (map snd counts)