Test name | Executions per second |
---|---|
Filter | 19.0 Ops/sec |
Group by | 1115.9 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var max = 5000;
var arr = [];
for (let i = 0; i < max; i++) {
arr.push({ value: i});
// create an occasional duplicate
if (i % 10 === 0) {
arr.push({ value: i});
}
}
var duplicates = arr.filter((item, _, items) => items.find(dupItem => dupItem.value === item.value));
var grouped = _.groupBy(arr, item => item.value);
var duplicates1 = _.flatten(_.filter(grouped, group => group.length > 1));