{"ScriptPreparationCode":"var data = [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}, {a: 7}, {a: 8}, {a: 1}];","TestCases":[{"Name":"lodash","Code":"_.uniqBy(data, \u0027a\u0027);","IsDeferred":false},{"Name":"javascript","Code":"const sortBy = (key) =\u003E {\r\n return (a, b) =\u003E (a[key] \u003E b[key]) ? 1 : (b[key] \u003E a[key] ? -1 : 0);\r\n};\r\n\r\nconst uniqBy = (arr, a) =\u003E {\r\n arr.sort(sortBy(a));\r\n const arr1 = [];\r\n arr1.push(arr[0]);\r\n for (let index = 1; index \u003C arr.length; index\u002B\u002B) {\r\n if (arr[index-1] \u0026\u0026 arr[index -1].a !== arr[index].a) {\r\n arr1.push(arr[index]);\r\n }\r\n }\r\n return arr1;\r\n}\r\nuniqBy(data, \u0027a\u0027)","IsDeferred":false},{"Name":"native","Code":"function uniqueBy(arr, prop){\r\n const record = []\r\n const seen = {}\r\n for (let i = 0, len = arr.length; i \u003C len; \u002B\u002Bi) { // Notice the len = arr.length\r\n const item = arr[i]\r\n const val = item[prop]\r\n if (!seen[val]) {\r\n seen[val] = 1\r\n record.push(item)\r\n }\r\n }\r\n}\r\n\r\nuniqueBy(data, \u0027a\u0027)","IsDeferred":false}]}