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

MapSet Drills

exercises/mapset_drills.livemd

MapSet Drills

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue Maps, Mapsets, And Keyword ListsFibonacci Sequence

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.

MapSet.new([1, 2, 3])

Use MapSet.new/2 to create an empty mapset.

MapSet.new([])

Use MapSet.new/2 to create a mapset with the integers 1 to 10.

MapSet.new(1..10)

Use MapSet.new/2 to create a mapset with the integers 1 to 1000.

MapSet.new(1..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.new([%{}, 2, "3"])

MapSet.put/2

Use MapSet.put/2 to put the element "a" into the existing mapset.

mapset = MapSet.new(["b", "c"])
mapset = MapSet.put(mapset, "a")

Use MapSet.new/2 and MapSet.put/2 to put 1 into a MapSet containing the elements 2 and 3.

mapset = MapSet.new([2, 3])
mapset = MapSet.put(mapset, 1)

Use MapSet.put/2 twice with the element 1 on an empty mapset to demonstrate that the MapSet only contains unique values.

mapset = MapSet.new([])
mapset = MapSet.put(mapset, 1)
mapset = MapSet.put(mapset, 1)

MapSet.delete/2

Use MapSet.delete/2 to delete the 1 element from the following mapset.

mapset = MapSet.new([1])
mapset = MapSet.delete(mapset, 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 = MapSet.new(1..6)
mapset = MapSet.delete(mapset, 6)

MapSet.member?/2

Use MapSet.member?/2 to check if 1 is in the following mapset.

mapset = MapSet.new([1, 2, 3])
has_two = MapSet.member?(mapset, 1)

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.

mapset = MapSet.new(1..10)
has_eleven = MapSet.member?(mapset, 11)

Use MapSet.member?/2 to check if %{key: "value"} is in the following mapset.

mapset = MapSet.new([%{key: "value"}])
has_map = MapSet.member?(mapset, %{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])
mapset = MapSet.filter(mapset, fn ele -> is_integer(ele) end)

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.

mapset = MapSet.new(1..10)
mapset = MapSet.filter(mapset, fn ele -> rem(ele, 2) == 0 end)

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.filter(fn ele ->
  ele =~ "a"
end)

MapSet.equal?/2

Use MapSet.equal?/2 to check if the following mapset is equal to MapSet.new([1]).

mapset = MapSet.new([1])
is_equal = MapSet.equal?(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).

MapSet.equal?(MapSet.new([1, 2, 3, 4, 5]), 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.equal?(MapSet.new() |> MapSet.put(1), 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.

MapSet.subset?(MapSet.new([2, 3]), MapSet.new([1, 2, 3, 4]))

Use MapSet.subset?/2 to check if MapSet.new(["a"]) is a subset of MapSet.new(["a", "b"]).

MapSet.subset?(MapSet.new(["a"]), 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])
list = MapSet.to_list(mapset)

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish MapSet Drills exercise"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue Maps, Mapsets, And Keyword ListsFibonacci Sequence