Skip to content
loading...

re: Daily Challenge #187 - Most Sales VIEW POST

FULL DISCUSSION
 

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
code of conduct - report abuse