mirror of
https://github.com/rjNemo/exercism-elixir
synced 2026-06-06 02:16:48 +00:00
11 lines
472 B
Elixir
11 lines
472 B
Elixir
defmodule BoutiqueInventory do
|
|
def sort_by_price(inventory), do: Enum.sort_by(inventory, & &1.price, &(&1 <= &2))
|
|
|
|
def with_missing_price(inventory), do: Enum.filter(inventory, &(&1.price == nil))
|
|
|
|
def increase_quantity(%{quantity_by_size: qty} = item, count),
|
|
do: %{item | quantity_by_size: Enum.into(qty, %{}, fn {s, q} -> {s, q + count} end)}
|
|
|
|
def total_quantity(%{quantity_by_size: qty}),
|
|
do: Enum.reduce(qty, 0, fn {_, q}, total -> total + q end)
|
|
end
|