Add Lua code for chapter 5
This commit is contained in:
committed by
Aditya Bhargava
parent
5f2626c91b
commit
86785a0659
10
05_hash_tables/lua/01_price_of_groceries.lua
Normal file
10
05_hash_tables/lua/01_price_of_groceries.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
local book = {}
|
||||
-- an apple costs 67 cents
|
||||
book["apple"] = 0.67
|
||||
-- milk costs $1.49
|
||||
book["milk"] = 1.49
|
||||
book["avocado"] = 1.49
|
||||
|
||||
for key, value in pairs(book) do
|
||||
print(key .. ": " .. value)
|
||||
end
|
||||
13
05_hash_tables/lua/02_check_voter.lua
Normal file
13
05_hash_tables/lua/02_check_voter.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
local voted = {}
|
||||
function check_voter(name)
|
||||
if voted[name] then
|
||||
print("kick them out!")
|
||||
else
|
||||
voted[name] = true
|
||||
print("let them vote!")
|
||||
end
|
||||
end
|
||||
|
||||
check_voter("tom")
|
||||
check_voter("mike")
|
||||
check_voter("mike")
|
||||
Reference in New Issue
Block a user