Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- λ> pickMajorityUnsafe [3,1,2,2,1,3]
- 3
- λ> pickMajorityUnsafe [3,1,2,2,1]
- 1
- λ> pickMajorityUnsafe [3,2,2,1]
- 2
- import Data.List
- import Data.Monoid
- import Data.Ord
- pickMajorityUnsafe :: (Ord a) => [a] -> a
- pickMajorityUnsafe xs = head
- . head
- . sortBy (flip (comparing length) <> comparing originalIndex)
- . group
- . sort
- $ xs
- where
- originalIndex gs = head gs `elemIndex` xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement