Capil ka isi

Modul:table/compressSparseArray

Matan Wiktionary

Dokumentasi untuk modul ini dapat dibuat di Modul:table/compressSparseArray/doc

-- Imported from enwiktionary
-- Source: https://en.wiktionary.org/wiki/Module:table/compressSparseArray
-- License: CC BY-SA

local table_num_keys_module = "Module:table/numKeys"

local function num_keys(...)
	num_keys = require(table_num_keys_module)
	return num_keys(...)
end

--[==[
Given a list that may contain gaps (e.g. {1, 2, nil, 4}), returns a new gapless list in the same order.]==]
return function(t)
	local list, keys, i = {}, num_keys(t), 0
	while true do
		i = i + 1
		local k = keys[i]
		if k == nil then
			return list
		end
		list[i] = t[k]
	end
end