From e571d8717bd479fabbd4017e55394ad6f1870360 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 30 May 2024 22:04:34 +0200 Subject: lout --- tools/parse-layout.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tools') diff --git a/tools/parse-layout.js b/tools/parse-layout.js index f2443fd..b389669 100644 --- a/tools/parse-layout.js +++ b/tools/parse-layout.js @@ -430,6 +430,28 @@ remap_to_range(sets.map) remap_to_range(sets.suit) remap_to_range(sets.country) +function object_group_by(items, callback) { + let groups = {} + if (typeof callback === "function") { + for (let item of items) { + let key = callback(item) + if (key in groups) + groups[key].push(item) + else + groups[key] = [ item ] + } + } else { + for (let item of items) { + let key = item[callback] + if (key in groups) + groups[key].push(item) + else + groups[key] = [ item ] + } + } + return groups +} + delete sets.type.city sets.cities = arrays -- cgit v1.2.3