Test name | Executions per second |
---|---|
Array.prototype.reduce() | 7552938.5 Ops/sec |
_.uniqBy | 688939.8 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var workOrders = _.range(_.random(100)).map(x => ({
assignee: {
id: _.random(1, 10),
},
}));
workOrders.reduce((accumulator, workOrder) => {
if (workOrder.assignee === null) {
return accumulator;
}
const assigneeExists = accumulator.some(assignee => assignee.id === workOrder.assignee.id);
return assigneeExists === true ? accumulator : [accumulator, workOrder.assignee];
}, []);
_(workOrders).map('assignee').filter().uniqBy('id').value();