{"ScriptPreparationCode":"const data = [\r\n {\r\n \u0022id\u0022: \u0022HUB:SEA:07244d185647df49a\u0022,\r\n \u0022podType\u0022: \u0022ACCOUNT_EXECUTIVE_TO_SALES_DEVELOPER\u0022,\r\n \u0022primarySeats\u0022: [\r\n {\r\n \u0022managerUserLdap\u0022: \u0022ehazlehu\u0022,\r\n \u0022managerSeatName\u0022: \u0022MS-EMEA-Mgr-HUB-STG-002147\u0022,\r\n \u0022managerUserName\u0022: \u0022Emma Hazlehurst\u0022,\r\n \u0022managerSeatId\u0022: \u0022HUB:SEA:07244d185647df75b\u0022,\r\n \u0022userLdap\u0022: \u0022ahartle\u0022,\r\n \u0022userLevel\u0022: \u0022AE4\u0022,\r\n \u0022userName\u0022: \u0022Annabel Hartle\u0022,\r\n \u0022seatName\u0022: \u0022LTS-EMEA-AE4-HUB-STG-000001\u0022,\r\n \u0022seatId\u0022: \u0022HUB:SEA:07244d185647df515\u0022,\r\n \u0022podId\u0022: \u0022hub:pod:16fa6c18b93ad09e5\u0022,\r\n \u0022isPodDeleted\u0022: false,\r\n \u0022startDate\u0022: \u00222023-11-03\u0022,\r\n \u0022endDate\u0022: \u00222123-11-03\u0022,\r\n \u0022__typename\u0022: \u0022PrimarySeatInfo\u0022\r\n }\r\n ],\r\n \u0022secondarySeat\u0022: {\r\n \u0022managerUserLdap\u0022: \u0022alalor\u0022,\r\n \u0022managerSeatName\u0022: \u0022LSS-EMEA-Mgr-HUB-STG-005104\u0022,\r\n \u0022managerUserName\u0022: \u0022Alan Lalor\u0022,\r\n \u0022managerSeatId\u0022: \u0022HUB:SEA:07244d185647e0b02\u0022,\r\n \u0022userLdap\u0022: \u0022rcleary\u0022,\r\n \u0022userName\u0022: \u0022Rachel Cleary\u0022,\r\n \u0022userLevel\u0022: \u0022SD1\u0022,\r\n \u0022seatName\u0022: \u0022LSS-EMEA-SD1-HUB-STG-001786\u0022,\r\n \u0022seatId\u0022: \u0022HUB:SEA:07244d185647df49a\u0022,\r\n \u0022__typename\u0022: \u0022SecondarySeatInfo\u0022\r\n },\r\n \u0022__typename\u0022: \u0022PodSeatMapping\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u0022HUB:SEA:07244d185647df5fb\u0022,\r\n \u0022podType\u0022: \u0022ACCOUNT_EXECUTIVE_TO_SALES_DEVELOPER\u0022,\r\n \u0022primarySeats\u0022: [\r\n {\r\n \u0022managerUserLdap\u0022: \u0022bruczhan\u0022,\r\n \u0022managerSeatName\u0022: \u0022HUBBLE_NULL_DEFAULT_MANAGER_SEAT\u0022,\r\n \u0022managerUserName\u0022: \u0022Bruce Zhang\u0022,\r\n \u0022managerSeatId\u0022: \u0022hub:sea:f48b45186382c130f\u0022,\r\n \u0022userLdap\u0022: \u0022bdonley\u0022,\r\n \u0022userLevel\u0022: \u0022AE\u0022,\r\n \u0022userName\u0022: \u0022Brittany Huerta\u0022,\r\n \u0022seatName\u0022: \u0022TAL-APAC-AE2-HUB-STG-004492\u0022,\r\n \u0022seatId\u0022: \u0022HUB:SEA:07244d185647dfa68\u0022,\r\n \u0022podId\u0022: \u0022hub:pod:c2a000186086caf62\u0022,\r\n \u0022isPodDeleted\u0022: false,\r\n \u0022startDate\u0022: \u00222023-01-31\u0022,\r\n \u0022endDate\u0022: \u00222023-06-15\u0022,\r\n \u0022__typename\u0022: \u0022PrimarySeatInfo\u0022\r\n },\r\n {\r\n \u0022managerUserLdap\u0022: \u0022bruczhan\u0022,\r\n \u0022managerSeatName\u0022: \u0022HUBBLE_NULL_DEFAULT_MANAGER_SEAT\u0022,\r\n \u0022managerUserName\u0022: \u0022Bruce Zhang\u0022,\r\n \u0022managerSeatId\u0022: \u0022hub:sea:f48b45186382c130f\u0022,\r\n \u0022userLdap\u0022: \u0022jcorinea\u0022,\r\n \u0022userLevel\u0022: \u0022AE1\u0022,\r\n \u0022userName\u0022: \u0022Justin Corinealdi\u0022,\r\n \u0022seatName\u0022: \u0022LSS-EMEA-SD1-HUB-STG-006712\u0022,\r\n \u0022seatId\u0022: \u0022HUB:SEA:07244d185647e31eb\u0022,\r\n \u0022podId\u0022: \u0022HUB:POD:453eff18565b8f73b\u0022,\r\n \u0022isPodDeleted\u0022: false,\r\n \u0022startDate\u0022: \u00222023-01-16\u0022,\r\n \u0022endDate\u0022: \u00222023-06-15\u0022,\r\n \u0022__typename\u0022: \u0022PrimarySeatInfo\u0022\r\n }\r\n ],\r\n \u0022secondarySeat\u0022: {\r\n \u0022managerUserLdap\u0022: \u0022rhurh\u0022,\r\n \u0022managerSeatName\u0022: \u0022TAL-NA-Mgr-HUB-STG-005646\u0022,\r\n \u0022managerUserName\u0022: \u0022Rich Hurh\u0022,\r\n \u0022managerSeatId\u0022: \u0022HUB:SEA:07244d185647e24c9\u0022,\r\n \u0022userLdap\u0022: \u0022zvaldovinos\u0022,\r\n \u0022userName\u0022: \u0022Zoraida Valdovinos\u0022,\r\n \u0022userLevel\u0022: \u0022RM2\u0022,\r\n \u0022seatName\u0022: \u0022TAL-NA-SD1-HUB-STG-001533\u0022,\r\n \u0022seatId\u0022: \u0022HUB:SEA:07244d185647df5fb\u0022,\r\n \u0022__typename\u0022: \u0022SecondarySeatInfo\u0022\r\n },\r\n \u0022__typename\u0022: \u0022PodSeatMapping\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u0022HUB:SEA:07244d185647df76c\u0022,\r\n \u0022podType\u0022: \u0022ACCOUNT_EXECUTIVE_TO_SALES_DEVELOPER\u0022,\r\n \u0022primarySeats\u0022: [\r\n {\r\n \u0022managerUserLdap\u0022: \u0022bruczhan\u0022,\r\n \u0022managerSeatName\u0022: \u0022HUBBLE_NULL_DEFAULT_MANAGER_SEAT\u0022,\r\n \u0022managerUserName\u0022: \u0022Bruce Zhang\u0022,\r\n \u0022managerSeatId\u0022: \u0022hub:sea:f48b45186382c130f\u0022,\r\n \u0022userLdap\u0022: \u0022jcorinea\u0022,\r\n \u0022userLevel\u0022: \u0022AE1\u0022,\r\n \u0022userName\u0022: \u0022Justin Corinealdi\u0022,\r\n \u0022seatName\u0022: \u0022LSS-EMEA-SD1-HUB-STG-006712\u0022,\r\n \u0022seatId\u0022: \u0022HUB:SEA:07244d185647e31eb\u0022,\r\n \u0022podId\u0022: \u0022HUB:POD:453eff18565b8f73b\u0022,\r\n \u0022isPodDeleted\u0022: false,\r\n \u0022startDate\u0022: \u00222023-01-16\u0022,\r\n \u0022endDate\u0022: \u00222023-06-15\u0022,\r\n \u0022__typename\u0022: \u0022PrimarySeatInfo\u0022\r\n }\r\n ],\r\n \u0022secondarySeat\u0022: {\r\n \u0022managerUserLdap\u0022: \u0022cfrenzel\u0022,\r\n \u0022managerSeatName\u0022: \u0022HS-EMEA-Mgr-HUB-STG-006289\u0022,\r\n \u0022managerUserName\u0022: \u0022Christian Frenzel\u0022,\r\n \u0022managerSeatId\u0022: \u0022HUB:SEA:07244d185647e0d72\u0022,\r\n \u0022userLdap\u0022: \u0022tgaiswin\u0022,\r\n \u0022userName\u0022: \u0022Thoman Gaiswinkler\u0022,\r\n \u0022userLevel\u0022: \u0022AE3\u0022,\r\n \u0022seatName\u0022: \u0022HS-EMEA-AE3-HUB-STG-002179\u0022,\r\n \u0022seatId\u0022: \u0022HUB:SEA:07244d185647df76c\u0022,\r\n \u0022__typename\u0022: \u0022SecondarySeatInfo\u0022\r\n },\r\n \u0022__typename\u0022: \u0022PodSeatMapping\u0022\r\n }\r\n];\r\n\r\nconst groupByPrimarySeatIdLodash = (data) =\u003E {\r\n const flattened = _.flatMap(data, (item) =\u003E {\r\n if (!item.primarySeats) return [];\r\n return item.primarySeats.map((seat) =\u003E {\r\n return {\r\n primarySeatId: seat?.seatId ?? \u0027\u0027,\r\n data: item\r\n };\r\n });\r\n });\r\n\r\n const grouped = _.groupBy(flattened, \u0027primarySeatId\u0027);\r\n return _.mapValues(grouped, (items) =\u003E items.map((item) =\u003E item.data));\r\n};\r\n\r\n/**\r\n * Same as above but using plain javascript\r\n */\r\nconst groupByPrimarySeatId = (data) =\u003E {\r\n const groups = {};\r\n\r\n data.forEach((record) =\u003E {\r\n if (!record.primarySeats) return;\r\n record.primarySeats.forEach((seat) =\u003E {\r\n const seatId = seat?.seatId ?? \u0027\u0027;\r\n if (!groups[seatId]) {\r\n groups[seatId] = [];\r\n }\r\n\r\n groups[seatId].push(record);\r\n });\r\n });\r\n\r\n return groups;\r\n};","TestCases":[{"Name":"js","Code":"groupByPrimarySeatId(data)","IsDeferred":false},{"Name":"lodash","Code":"groupByPrimarySeatIdLodash(data)","IsDeferred":false}]}