MapSet Drills
Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.8.0", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"}
])
Navigation
MapSet Drills
Drills help you develop familiarity and muscle memory with syntax through repeated exercises. Unlike usual problems, Drills are not intended to develop problem solving skills, they are purely for developing comfort and speed.
This set of drills is for MapSets follow the instructions for each drill and complete them as quickly as you can.
MapSet.new/2
Use MapSet.new/2 to create a mapset with the integers 1, 2, and 3.
Use MapSet.new/2 to create an empty mapset.
Use MapSet.new/2 to create a mapset with the integers 1 to 10.
Use MapSet.new/2 to create a mapset with the integers 1 to 1000.
Use MapSet.new/2 to create a mapset with the same elements as the list below.
list = [%{}, 2, "3"]
Use MapSet.new/2 to create a mapset with the elements %{key: "value"}, [one: 1], and {1, 2, 3}.
MapSet.put/2
Use MapSet.put/2 to put the element "a" into the existing mapset.
mapset = MapSet.new(["b", "c"])
Use MapSet.new/2 and MapSet.put/2 to put 1 into a MapSet containing the elements 2 and 3.
Use MapSet.put/2 twice with the element 1 on an empty mapset to demonstrate that the MapSet only contains unique values.
MapSet.delete/2
Use MapSet.delete/2 to delete the 1 element from the following mapset.
mapset = MapSet.new([1])
Use MapSet.delete/2 and MapSet.new/2 to create a mapset with elements from 1 to 6 then delete the 6 element.
MapSet.member?/2
Use MapSet.member?/2 to check if 1 is in the following mapset.
mapset = MapSet.new([1, 2, 3])
Use MapSet.new/2 to create a mapset with elements from 1 to 10. Then use MapSet.member?/2 to check if 11 is in the mapset.
Use MapSet.member?/2 to check if %{key: "value"} is in the following mapset.
mapset = MapSet.new([%{key: "value"}])
MapSet.filter/2
Use MapSet.filter/2 to filter the following mapset and make a mapset with only integers.
mapset = MapSet.new(["a", "b", "c", 1, 2, 3])
Use MapSet.new/2 and MapSet.filter/2 to create a mapset with integers from 1 to 10, then filter it to make a mapset with only even numbers.
Use MapSet.filter/2 to filter the following mapset to only include strings containing the letter "a".
MapSet.new(["apple", "orange", "pear", "banana", "cherry", "fruit"])
MapSet.equal?/2
Use MapSet.equal?/2 to check if the following mapset is equal to MapSet.new([1]).
mapset = MapSet.new([1])
Use MapSet.equal?/2 to check if MapSet.new([1, 2, 3, 4, 5]) is equal to MapSet.new(1..5).
Use MapSet.new/2 to create an empty mapset, then MapSet.put/2 to add 1 to the mapset.
Then use MapSet.equal?/2 to check if the resulting mapset equals MapSet.new([1])
MapSet.subset?/2
Use MapSet.subset?/2 to check if MapSet.new([2, 3]) is a subset of MapSet.new([1, 2, 3, 4]). The result should be true.
Use MapSet.subset?/2 to check if MapSet.new(["a"]) is a subset of MapSet.new(["a", "b"]).
MapSet.to_list/1
Use MapSet.to_list/1 to convert the following mapset into a list.
mapset = MapSet.new([1, 2, 3])
Mark As Completed
file_name = Path.basename(Regex.replace(~r/#.+/, __ENV__.file, ""), ".livemd")
save_name =
case Path.basename(__DIR__) do
"reading" -> "mapset_drills_reading"
"exercises" -> "mapset_drills_exercise"
end
progress_path = __DIR__ <> "/../progress.json"
existing_progress = File.read!(progress_path) |> Jason.decode!()
default = Map.get(existing_progress, save_name, false)
form =
Kino.Control.form(
[
completed: input = Kino.Input.checkbox("Mark As Completed", default: default)
],
report_changes: true
)
Task.async(fn ->
for %{data: %{completed: completed}} <- Kino.Control.stream(form) do
File.write!(
progress_path,
Jason.encode!(Map.put(existing_progress, save_name, completed), pretty: true)
)
end
end)
form
Commit Your Progress
Run the following in your command line from the curriculum folder to track and save your progress in a Git commit.
Ensure that you do not already have undesired or unrelated changes by running git status or by checking the source control tab in Visual Studio Code.
$ git checkout -b mapset-drills-exercise
$ git add .
$ git commit -m "finish mapset drills exercise"
$ git push origin mapset-drills-exercise
Create a pull request from your mapset-drills-exercise branch to your solutions branch.
Please do not create a pull request to the DockYard Academy repository as this will spam our PR tracker.
DockYard Academy Students Only:
Notify your teacher by including @BrooklinJazz in your PR description to get feedback.
You (or your teacher) may merge your PR into your solutions branch after review.
If you are interested in joining the next academy cohort, sign up here to receive more news when it is available.
Up Next
| Previous | Next |
|---|---|
| Maps, MapSets, and Keyword Lists | MapSet Product Filters |