Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0
Firefox 103
Mac OS X 10.15
Desktop
2 years ago
Test name Executions per second
Array.prototype.reduce() 7552938.5 Ops/sec
_.uniqBy 688939.8 Ops/sec
HTML Preparation code:
AخA
 
1
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
var workOrders = _.range(_.random(100)).map(x => ({
  assignee: {
    id: _.random(1, 10),
  },
}));
Tests:
  • Array.prototype.reduce()

     
    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];
    }, []);
  • _.uniqBy

     
    _(workOrders).map('assignee').filter().uniqBy('id').value();