Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Item Finder

item_search.livemd

Item Finder

Mix.install([
  {:kino, github: "livebook-dev/kino", override: true},
  {:kino_lab, "~> 0.1.0-dev", github: "jonatanklosko/kino_lab"},
  {:vega_lite, "~> 0.1.4"},
  {:kino_vega_lite, "~> 0.1.1"},
  {:benchee, "~> 0.1"},
  {:ecto, "~> 3.7"},
  {:math, "~> 0.7.0"},
  {:faker, "~> 0.17.0"},
  {:utils, path: "#{__DIR__}/../utils"},
  {:tested_cell, git: "https://github.com/BrooklinJazz/tested_cell"}
])

Navigation

Return Home Report An Issue

Item Search

You are building a game with a search feature for a massive list of magical items.

Players should be able to search for items that match certain properties. They should be able to search by type, effect, level, size, and style in a keyword list.

By default, all_items/2 should find items that match all filters. If there are no filters it should find all items.

items = [
  %{type: "sword", effect: "healing", level: 1, size: 1, style: "holy"},
  %{type: "mace", effect: "protection", level: 2, size: 3, style: "dark"}
]

Search.all_items(items, [])

[
  %{type: "sword", effect: "healing", level: 1, size: 1, style: "holy"},
  %{type: "mace", effect: "protection", level: 2, size: 3, style: "dark"}
]

Search.all_items(items, type: "sword", effect: "healing")
[%{type: "sword", effect: "healing", level: 1, size: 1, style: "holy"}]

Users should be able to enter an inclusive: true filter to find items that match any of the properties.

Search.all_items(items, type: "sword", effect: "speed", inclusive: true)
[{type: "sword", effect: "healing", level: 1, size: 1, style: "holy"}]

Enter your answer in the Elixir cell below.

defmodule Search do
  def all_items(items, filters) do
  end
end

Utils.feedback(:item_generator_search, Search)

Commit Your Progress

Run the following in your command line from the project folder to track and save your progress in a Git commit.

$ git add .
$ git commit -m "finish item search exercise"