본문으로 이동

모듈:table/sparseConcat

위키낱말사전, 말과 글의 누리

이 모듈에 대한 설명문서는 모듈:table/sparseConcat/설명문서에서 만들 수 있습니다

local table_sparse_ipairs_module = "Module:table/sparseIpairs"

local concat = table.concat

local function sparse_ipairs(...)
	sparse_ipairs = require(table_sparse_ipairs_module)
	return sparse_ipairs(...)
end

--[==[
Concatenates all values in a table that are indexed by a number, in order.
* {sparseConcat{ a, nil, c, d }} => {"acd"}
* {sparseConcat{ nil, b, c, d }} => {"bcd"}]==]
return function(t, sep, i, j)
	local list, k = {}, 0
	for _, v in sparse_ipairs(t) do
		k = k + 1
		list[k] = v
	end
	return concat(list, sep, i, j)
end