Skip to content

Commit 0c94244

Browse files
spadarjauhienegonSchiele
authored andcommitted
Add Elixir examples for hash tables
1 parent 5d965d0 commit 0c94244

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Map, only: [put: 3]
2+
3+
book =
4+
%{}
5+
|> put("apple", 0.67)
6+
|> put("milk", 1.49)
7+
|> put("avocado", 1.49)
8+
9+
IO.inspect(book)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule Voting do
2+
def check_voter(voters_map, name) do
3+
if Map.has_key?(voters_map, name) do
4+
IO.puts("kick them out!")
5+
else
6+
IO.puts("let them vote!")
7+
Map.put(voters_map, name, true)
8+
end
9+
end
10+
end
11+
12+
Voting.check_voter(%{}, "tom")
13+
|> Voting.check_voter("mike")
14+
|> Voting.check_voter("mike")

0 commit comments

Comments
 (0)