Add Elixir examples for hash tables
This commit is contained in:
committed by
Aditya Bhargava
parent
5d965d0b8a
commit
0c9424455e
9
05_hash_tables/elixir/01_price_of_groceries.exs
Normal file
9
05_hash_tables/elixir/01_price_of_groceries.exs
Normal file
@@ -0,0 +1,9 @@
|
||||
import Map, only: [put: 3]
|
||||
|
||||
book =
|
||||
%{}
|
||||
|> put("apple", 0.67)
|
||||
|> put("milk", 1.49)
|
||||
|> put("avocado", 1.49)
|
||||
|
||||
IO.inspect(book)
|
||||
14
05_hash_tables/elixir/02_check_voter.exs
Normal file
14
05_hash_tables/elixir/02_check_voter.exs
Normal file
@@ -0,0 +1,14 @@
|
||||
defmodule Voting do
|
||||
def check_voter(voters_map, name) do
|
||||
if Map.has_key?(voters_map, name) do
|
||||
IO.puts("kick them out!")
|
||||
else
|
||||
IO.puts("let them vote!")
|
||||
Map.put(voters_map, name, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Voting.check_voter(%{}, "tom")
|
||||
|> Voting.check_voter("mike")
|
||||
|> Voting.check_voter("mike")
|
||||
Reference in New Issue
Block a user