end
local function isAny(args, suffix) ▼
local months = { 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' }
local monthToNumber = require("Module:TableTools").invert(months)
for k_, vmonth in pairsipairs( argsmonths) do ▼
if stripToNil(args[month .. suffix]) then
local autoSubtableMt = {
__index = function(self, key)
local val = {}
self[key] = val
end
}
local function unAutoSubtable(t)
t.unAutoSubtable = nil
return setmetatable(t, nil)
end
local function makeAutoSubtabler(t)
t = t or {}
t.unAutoSubtable = unAutoSubtable
return setmetatable(t, autoSubtableMt)
end
-- Generate tables (arrays) for monthly values for each statistic from the args
-- table.
local generateMonthTables = require("Module:fun").memoize(function (args)
local tables = makeAutoSubtabler()
▲ for k, v in pairs(args) do
local month, suffix = k:match("^(%u%l%l) (.+)$")
if month then
local monthNumber = monthToNumber[month]
if monthNumber then
tables[suffix][monthNumber] = stripToNil(v)
end
end
end
return tables:unAutoSubtable()
end)
▲local function isAny(args, suffix)
local monthTable = generateMonthTables(args)[suffix:gsub("^ ", "")]
return monthTable ~= nil
end
|