Enum
모듈을 배우는 문제였다. 개념 문제여서 딱히 코멘트할 내용은 없음!
defmodule BoutiqueInventory do
def sort_by_price(inventory) do
Enum.sort_by(inventory, &(&1.price))
end
def with_missing_price(inventory) do
Enum.filter(inventory, &(is_nil(&1.price)))
end
def update_names(inventory, old_word, new_word) do
Enum.map(inventory, fn %{name: name} = record ->
%{record | name: String.replace(name, old_word, new_word)}
end)
end
def increase_quantity(%{quantity_by_size: q} = item, count) do
%{item | quantity_by_size: Map.new(q, fn {k, v} -> {k, v + count} end)}
end
def total_quantity(%{quantity_by_size: q}) do
Enum.reduce(q, 0, fn {_k, v}, acc -> v + acc end)
end
end
'호두나무 공방 > Exercism in Elixir' 카테고리의 다른 글
Newsletter - Exercism in Elixir (0) | 2022.05.03 |
---|---|
File Sniffer - Exercism in Elixir (0) | 2022.05.02 |
Basketball Website - Exercism in Elixir (0) | 2022.04.28 |
Resistor Color Trio - Exercism in Elixir (0) | 2022.04.22 |
Sublist - Exercism in Elixir (0) | 2022.04.21 |