假设我有一个清单Vendors:阿斯达、乐购、Spar。
我有一个清单Sources(或者这个类比中的供应商):家乐氏(Kellogg)、吉百利(Cadbury)、雀巢(Nestle)、强生(Johnsons)、帮宝适(Pampers)、Simple 等(有大约 20 个定义的列表)。
数据流中的其他地方。我正在返回一个结果,对于每个供应商、多个不同的事物来说,该结果是“是”/“否”。
例如:阿斯达:仅英国=“是”; Spar:仅限英国 =“否”等。
在这个特定部分中,我正在整理结果。
大多数情况下,供应商的来源是否重叠并不重要。所以我只能说:
function concatResults(x) -- concats the result of "x" for each vendor
local pathAsda = *this is where I call the path location specific to Asda*
local pathTesco = *this is where I call the path location specific to Tesco*
local pathSpar = *this is where I call the path location specific to Spar*
if (pathAsda == "Yes" or pathTesco == "Yes" or pathSpar == "Yes") then
return "Yes"
else
return "No"
end
end
ukOnlyAgr = concatResults("ukOnly")
Great!
现在,假设我想做一些更复杂的事情。
我想知道有多少独特的供应商在提供巧克力和谷物食品。下面的示例将在流程中进一步使用以产生事实suppliesSweet
,仅当至少涉及两个来源(供应商)并且它们必须至少供应巧克力时。这将为每个供应商单独完成(请假设我已经根据输入数据定义了变量:
if (suppliesChoc > 0 and suppliesCereal > 0 and numSources > 1) or (suppliesChoc > 1) then
then suppliesSweet = "Yes"
else suppliesSweet = "No"
end
还不是问题。
当我尝试跨供应商汇总这些结果时,问题就出现了(就像我之前所做的那样)ukOnly
).
我已经使用了以下功能:
table.contains = function(t, value) -- Finds if "value" exists inside the table "t"
for index = 1, #t do
if t[index] == value then
return index
end
end
end
并正在考虑创建这个:
table.overlap = function(t,g) -- Finds if tables "g" and "t" have any overlapping values
for i=1,#t do
if table.contains(g,t[i]) then
return true
else
return false
end
end
end
但我只是不确定从那里去哪里。
您可以假设我已经获得了每个供应商的独特来源列表,并且我不介意我们是否过度限制。 IE。如果两个供应商之间有任何来源重叠,那么整个结果就会无效。
你也可以假设我有每个“事实”:suppliesChoc
, suppliesCereal
, numSources
and suppliesSweet
对于每个供应商单独返回的。