boutique-suggestions
This commit is contained in:
23
elixir/boutique-suggestions/lib/boutique_suggestions.ex
Normal file
23
elixir/boutique-suggestions/lib/boutique_suggestions.ex
Normal file
@@ -0,0 +1,23 @@
|
||||
defmodule BoutiqueSuggestions do
|
||||
@moduledoc """
|
||||
Your work at the online fashion boutique store continues. You come up with the idea for a website feature where an outfit is suggested to the user. While you want to give lots of suggestions, you don't want to give bad suggestions, so you decide to use a list comprehension since you can easily generate outfit combinations, then filter them by some criteria.
|
||||
"""
|
||||
|
||||
@type boutique_item() :: %{item_name: String.t(), price: float(), base_color: String.t()}
|
||||
|
||||
@doc """
|
||||
Generate carthesian list of recomended product pairs Filter out clashing outfits. Using maximum_price in the options keyword list for filter products by price
|
||||
"""
|
||||
|
||||
@spec get_combinations([boutique_item()], [boutique_item()], Keyword.t()) :: [{boutique_item(), boutique_item()}]
|
||||
def get_combinations(tops, bottoms, options \\ [{:maximum_price, 100}]) do
|
||||
maximum_price = Keyword.get(options, :maximum_price, 100.0)
|
||||
|
||||
for top <- tops,
|
||||
bottom <- bottoms,
|
||||
top.base_color != bottom.base_color,
|
||||
top.price + bottom.price <= maximum_price do
|
||||
{top, bottom}
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user