Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
uniqBy performance and map
(version: 0)
lodash vs javascript
Comparing performance of:
lodash vs javascript vs map
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script>https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.core.js</script>
Script Preparation code:
var data = [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}, {a: 7}, {a: 8}, {a: 1}];
Tests:
lodash
_.uniqBy(data, 'a');
javascript
const sortBy = (key) => { return (a, b) => (a[key] > b[key]) ? 1 : (b[key] > a[key] ? -1 : 0); }; const uniqBy = (arr, a) => { arr.sort(sortBy(a)); const arr1 = []; arr1.push(arr[0]); for (let index = 1; index < arr.length; index++) { if (arr[index-1] && arr[index -1].a !== arr[index].a) { arr1.push(arr[index]); } } return arr1; } uniqBy(data, 'a')
map
const uniqBy = (arr, predicate) => { const cb = typeof predicate === 'function' ? predicate : (o) => o[predicate]; return [...arr.reduce((map, item) => { const key = (item === null || item === undefined) ? item : cb(item); map.has(key) || map.set(key, item); return map; }, new Map()).values()]; }; const sourceArray = [ { id: 1, name: 'bob' }, { id: 1, name: 'bill' }, null, { id: 1, name: 'bill' } , { id: 2,name: 'silly'}, { id: 2,name: 'billy'}, null, undefined ]; uniqBy(data, 'a')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash
javascript
map
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
uniqBy performance
uniqBy vs stringify performance
uniqBy performance ttt
uniqBy performance lodash vs native
Comments
Confirm delete:
Do you really want to delete benchmark?