{"ScriptPreparationCode":"var groups = Array.apply(null, {length: 32}).map(v =\u003E (Math.random() \u002B 1).toString(36).substr(2))\r\nvar data = Array.apply(null, {length: 10_000}).map((v,id) =\u003E ({id, group: groups[Math.random() * groups.length | 0]}))\r\n","TestCases":[{"Name":"reduce with spread","Code":"function groupByReduce(objectArray, property) {\r\n return objectArray.reduce((acc, obj) =\u003E {\r\n const key = obj[property];\r\n const curGroup = acc[key] ?? [];\r\n\r\n return { ...acc, [key]: [...curGroup, obj] };\r\n }, {});\r\n}\r\ngroupByReduce(data, \u0027group\u0027);\r\n","IsDeferred":false},{"Name":"for...of with push","Code":"function groupByFor(data, keyProperty){\r\n const groups = {}\r\n for(const entry of data){\r\n const groupId = entry[keyProperty];\r\n if(!groups[groupId]){\r\n groups[groupId] = [];\r\n }\r\n groups[groupId].push(entry);\r\n }\r\n return groups;\r\n}\r\ngroupByFor(data, \u0027group\u0027)\r\n","IsDeferred":false}]}