Elixir:
defmodule Day74 do def eligible(customers, min_orders, min_price) do for customer = {_, orders} <- customers, Enum.count(orders, &(&1 >= min_price)) >= min_orders, into: %{}, do: customer end end
Tests:
defmodule Day74Test do use ExUnit.Case test "5 of $20" do customers = %{ "John Doe" => [22, 30, 11, 17, 15, 52, 27, 12], "Jane Doe" => [5, 17, 30, 33, 40, 22, 26, 10, 11, 45] } assert %{"Jane Doe" => _} = Day74.eligible(customers, 5, 20) end test "2 of $50" do customers = %{ "Joey Bonzo" => [22, 67, 53, 29], "Jennifer Bonzo" => [51, 19] } assert %{"Joey Bonzo" => _} = Day74.eligible(customers, 2, 50) end test "3 of $15" do customers = %{ "Natsumi Sakamoto" => [15, 15, 14], "Gorou Hironaka" => [15, 15, 15], "Shinju Tanabe" => [120, 240] } assert %{"Gorou Hironaka" => _} = Day74.eligible(customers, 3, 15) end end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Elixir:
Tests: