Advertisement
Guest User

Untitled

a guest
Dec 5th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. λ> pickMajorityUnsafe [3,1,2,2,1,3]
  2. 3
  3. λ> pickMajorityUnsafe [3,1,2,2,1]
  4. 1
  5. λ> pickMajorityUnsafe [3,2,2,1]
  6. 2
  7.  
  8. import Data.List
  9. import Data.Monoid
  10. import Data.Ord
  11.  
  12. pickMajorityUnsafe :: (Ord a) => [a] -> a
  13. pickMajorityUnsafe xs = head
  14.                       . head
  15.                       . sortBy (flip (comparing length) <> comparing originalIndex)
  16.                       . group
  17.                       . sort
  18.                       $ xs
  19.   where
  20.     originalIndex gs = head gs `elemIndex` xs
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement