diff --git a/util.lua b/util.lua index 8347433..3c152d5 100644 --- a/util.lua +++ b/util.lua @@ -234,4 +234,18 @@ function Aux.util.money_string(money) return format(GSC_1, c) end end -end \ No newline at end of file +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