{"ScriptPreparationCode":"var arr1 = [];\r\nvar arr2 = [];\r\n\r\nfor (i = 0; i \u003C 10000; i\u002B\u002B) {\r\n var obj = {\r\n id: Math.random().toString(36).substr(2, 5),\r\n name: Math.random().toString(36).substr(2, 5)\r\n };\r\n arr1.push(obj);\r\n}\r\n\r\nfor (i = 0; i \u003C arr1.length; i\u002B\u002B) {\r\n var obj = {\r\n id: Math.random() \u003C 0.5 ? arr1[i].id : Math.random().toString(36).substr(2, 5),\r\n name: Math.random().toString(36).substr(2, 5),\r\n role: [\u0027ADMIN\u0027, \u0027DEV\u0027, \u0027MANAGER\u0027, \u0027HR\u0027, \u0027DEV_OPS\u0027][Math.floor(Math.random() * 5)]\r\n };\r\n arr2.push(obj);\r\n}","TestCases":[{"Name":"ES6 map \u002B find","Code":"const mergeByKey = (firstArr, secondArr, key) =\u003E {\r\n return firstArr.map(initialObject =\u003E {\r\n const dataToExtend = secondArr.find(dataToExtend =\u003E initialObject[key] === dataToExtend[key]);\r\n if (dataToExtend) {\r\n return { ...initialObject, ...dataToExtend };\r\n }\r\n return initialObject;\r\n });\r\n};\r\n\r\nvar result = mergeByKey(arr1, arr2, \u0027id\u0027);","IsDeferred":false},{"Name":"Lodash","Code":"const mergeByKey = (firstArr, secondArr, key) =\u003E {\r\n return _(firstArr)\r\n .keyBy(key)\r\n .merge(_.keyBy(secondArr, key))\r\n .values()\r\n .value()\r\n};\r\n\r\nvar result = mergeByKey(arr1, arr2, \u0027id\u0027);","IsDeferred":false},{"Name":"Reduce","Code":"const mergeByKey3 = (firstArr, secondArr, key) =\u003E {\r\n\treturn [...firstArr.concat(secondArr).reduce((m, o) =\u003E\r\n\t\t\tm.set(o[key], Object.assign(m.get(o[key]) || {}, o))\r\n\t\t, new Map()).values()]\r\n};","IsDeferred":false}]}