{"ScriptPreparationCode":"var data = [\r\n { name: \u0027pi\u0027, value: 3.14 },\r\n { name: \u0027hundred\u0027, value: 100 },\r\n { name: \u0027truthy\u0027, value: true },\r\n { name: \u0027falsy\u0027, value: false },\r\n { name: \u0027estring\u0027, value: \u00272.71828\u0027 },\r\n];\r\n\r\n\r\nfor(let i =0; i\u003C1000; i\u002B\u002B){\r\n\tdata.push({\r\n name: \u0060i-${i}\u0060,\r\n value: i \u002B (i*10) \u002B (i*100),\r\n junk1: \u0027junk\u0027,\r\n junk2: 123,\r\n junk3: \u0027morejunk\u0027,\r\n junk4: \u0027evenmore\u0027,\r\n junk5: 345,\r\n junk6: 789,\r\n junk7: \u0027blah\u0027,\r\n junk8: \u0027baasdsadsadassdsadasdsa dsasdfdsfaascacf afaw\u0027,\r\n junk9: \u0027badadadadadadad\u0027,\r\n junk10: false,\r\n junk11: true,\r\n junk12: null\r\n })\r\n}\r\n\r\n\r\nvar keyBy = (array, fn) =\u003E {\r\n return array.reduce((acc, value) =\u003E {\r\n acc[fn(value)] = value;\r\n return acc;\r\n }, {});\r\n};\r\n\r\nvar keyByForEach = (array, fn) =\u003E {\r\n var acc = {};\r\n _.forEach(array, (value) =\u003E {\r\n acc[fn(value)] = value;\r\n });\r\n return acc;\r\n};\r\n\r\nvar keyByForLoop = (array, fn) =\u003E {\r\n var acc = {};\r\n for (let i = 0; i \u003C array.length; i\u002B\u002B) {\r\n acc[fn(array[i])] = array[i];\r\n }\r\n return acc;\r\n};","TestCases":[{"Name":"lodash/keyBy","Code":"_.keyBy(data, (v) =\u003E v.name);","IsDeferred":false},{"Name":"keyBy with native reduce","Code":"keyBy(data, (v) =\u003E v.name);","IsDeferred":false},{"Name":"keyBy with forEach","Code":"keyByForEach(data, (v) =\u003E v.name);","IsDeferred":false},{"Name":"keyBy with for loop","Code":"keyByForLoop(data, (v) =\u003E v.name);","IsDeferred":false}]}