{"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":"map","Code":"const uniqBy = (arr, predicate) =\u003E {\r\n const cb = typeof predicate === \u0027function\u0027 ? predicate : (o) =\u003E o[predicate];\r\n \r\n return [...arr.reduce((map, item) =\u003E {\r\n const key = (item === null || item === undefined) ? \r\n item : cb(item);\r\n \r\n map.has(key) || map.set(key, item);\r\n \r\n return map;\r\n }, new Map()).values()];\r\n};\r\n\r\nconst sourceArray = [ \r\n { id: 1, name: \u0027bob\u0027 },\r\n { id: 1, name: \u0027bill\u0027 },\r\n null,\r\n { id: 1, name: \u0027bill\u0027 } ,\r\n { id: 2,name: \u0027silly\u0027},\r\n { id: 2,name: \u0027billy\u0027},\r\n null,\r\n undefined\r\n];\r\nuniqBy(data, \u0027a\u0027)","IsDeferred":false}]}