added group by utility
This commit is contained in:
@@ -234,4 +234,18 @@ function Aux.util.money_string(money)
|
||||
return format(GSC_1, c)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Aux.util.group_by(tables, keys)
|
||||
local groups = {}
|
||||
Aux.util.map(tables, function(table)
|
||||
for _, group in ipairs(groups) do
|
||||
if Aux.util.all(keys, function(key) table[key] == group[1][key] end) then
|
||||
tinsert(group, table)
|
||||
return
|
||||
end
|
||||
end
|
||||
tinsert(groups, { table })
|
||||
end)
|
||||
return groups
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user