본문으로 이동

모듈:table/numKeys

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

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

local math_module = "Module:math"

local pairs = pairs
local sort = table.sort

local function is_positive_integer(...)
	is_positive_integer = require(math_module).is_positive_integer
	return is_positive_integer(...)
end

--[==[
Given a table, return an array containing all positive integer keys, sorted either in numerical order, or using a custom `keySort` function.]==]
return function(t, keySort)
	local nums, i = {}, 0
	for k in pairs(t) do
		if is_positive_integer(k) then
			i = i + 1
			nums[i] = k
		end
	end
	-- No need for [[Module:math/compare]], as the default is adequate for integers.
	sort(nums, keySort)
	return nums
end