Skip to content
loading...

re: Daily Challenge #187 - Most Sales VIEW POST

FULL DISCUSSION
 

Elixir

def get_max_revenue(products, amounts, prices) do
  list = Enum.zip([ products, amounts, prices ])
    |> Enum.map(fn { product, amount, price } -> { product, amount * price } end)
    |> Enum.sort(fn { _, r1 }, { _, r2 } -> r1 >= r2 end)
  first = list
    |> List.first
    |> (fn { _, revenue } -> revenue end).()
  Enum.take_while(list, fn { _, revenue } -> revenue == first end)
    |> Enum.map(fn { product, _ } -> product end)
end
code of conduct - report abuse