Module:table/sparseIpairs: Difference between revisions
Jump to navigation
Jump to search
m Protected "Module:table/sparseIpairs": Highly visible template/module ([Edit=Allow only template editors and administrators] (indefinite) [Move=Allow only template editors and administrators] (indefinite)) |
m 1 revision imported |
||
(No difference)
| |||
Latest revision as of 11:22, 21 April 2026
Documentation for this module may be created at Module:table/sparseIpairs/doc
local table_num_keys_module = "Module:table/numKeys"
local function num_keys(...)
num_keys = require(table_num_keys_module)
return num_keys(...)
end
--[==[
An iterator which works like `ipairs`, but which works for sparse arrays.]==]
return function(t)
local keys, i = num_keys(t), 0
return function()
i = i + 1
local k = keys[i]
if k ~= nil then
return k, t[k]
end
end
end