Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Array-length/Lua/array-length.lua
Normal file
18
Task/Array-length/Lua/array-length.lua
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
-- For tables as simple arrays, use the # operator:
|
||||
fruits = {"apple", "orange"}
|
||||
print(#fruits)
|
||||
|
||||
-- Note the # symbol does not work for non-integer-indexed tables:
|
||||
fruits = {fruit1 = "apple", fruit2 = "orange"}
|
||||
print(#fruits)
|
||||
|
||||
-- For this you can use this short function:
|
||||
function size (tab)
|
||||
local count = 0
|
||||
for k, v in pairs(tab) do
|
||||
count = count + 1
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
print(size(fruits))
|
||||
Loading…
Add table
Add a link
Reference in a new issue