February 2018
Beginner
200 pages
4h 37m
English
The EnchanterShop module should look like this:
| | defmodule EnchanterShop do |
| | def test_data do |
| | [ |
| | %{title: "Longsword", price: 50, magic: false}, |
| | %{title: "Healing Potion", price: 60, magic: true}, |
| | %{title: "Rope", price: 10, magic: false}, |
| | %{title: "Dragon's Spear", price: 100, magic: true}, |
| | ] |
| | end |
| | @enchanter_name "Edwin" |
| | |
| | def enchant_for_sale(items) do |
| | Enum.map(items, &transform/1) |
| | end |
| | |
| | defp transform(item = %{magic: true}), do: item |
| | defp transform(item) do |
| | %{ |
| | title: "#{@enchanter_name}'s #{item.title}", |
| | price: item.price * 3, |
Read now
Unlock full access