DEV Community

Discussion on: Daily Challenge #187 - Most Sales

Collapse
 
craigmc08 profile image
Craig McIlwrath • Edited

Haskell:

maximumsBy :: Ord b => (a -> b) -> [a] -> [a]
maximumsBy f = foldr g [] 
  where g x [] = [x]
        g x ys = case f x `compare` f (head ys) of
                   LT -> ys
                   EQ -> x : ys
                   GT -> [x]

bestSeller :: (Ord b, Num b) => [a] -> [b] -> [b] -> [a] 
bestSeller ns qs ps = map fst $ maximumsBy snd $
                      zip ns $ zipWith (*) qs ps