local numbers = {11, 2, 5, 7, 3}
-- unpack turns the array into arguments;
-- a million items are too many for it
local min_value = math.min(table.unpack(numbers))
-- min_value = 2
local max_value = math.max(table.unpack(numbers))
-- max_value = 11
-- The longest word: keep the largest so far
local words = {"bb", "a", "cccc"}
local longest = words[1]
for _, word in ipairs(words) do
if #word > #longest then
longest = word
end
end
-- longest = cccc
print("min_value = " .. min_value)
print("max_value = " .. max_value)
print("longest = " .. longest)
-- Empty array: no arguments, an error
local empty = {}
local ok, err =
pcall(math.max, table.unpack(empty))
-- ok = false
-- err = bad argument #1 to 'math.max'
-- (value expected)
print("ok = " .. tostring(ok))
print("err = " .. err)