DEV Community

Discussion on: Daily Challenge #187 - Most Sales

Collapse
 
avalander profile image
Avalander

Haskell

module MostSales where

import Data.List (groupBy, head, zip3, sortBy)


findHighest :: [String] -> [Int] -> [Int] -> [String]
findHighest a b c =
    ((map fst) . head . (groupBy value) . (sortBy compare') . (map total)) $ (zip3 a b c)
    where
        total (n, a, b)        = (n, a * b)
        value (_, x)           = ((==) x . snd)
        compare' (_, a) (_, b) = compare b a