Module:table/sparseConcat: Difference between revisions

From Linguifex
Jump to navigation Jump to search
m Protected "Module:table/sparseConcat": 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/sparseConcat/doc

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