Run details:
Mozilla/5.0 (Linux; Android 10; SM-G9650) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36
Chrome Mobile 87
Android
Mobile
3 years ago
Test name Executions per second
Filter 19.0 Ops/sec
Group by 1115.9 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:
x
 
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});
  }
}
Tests:
  • Filter

     
    var duplicates = arr.filter((item, _, items) => items.find(dupItem => dupItem.value === item.value));
  • Group by

     
    var grouped = _.groupBy(arr, item => item.value);
    var duplicates1 = _.flatten(_.filter(grouped, group => group.length > 1));