Test name | Executions per second |
---|---|
Javascript Set intersection | 0.0 Ops/sec |
Lodash intersection | 317247.6 Ops/sec |
Javascript Array intersection | 103712.8 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var first = [Array(100)].map(it => ~~(Math.random() * 1000));
var second = [Array(20)].map(it => ~~(Math.random() * 1000));
const firstSet = new Set(first);
const secondSet = new Set(second);
firstSet.filter(item => secondSet.has(item));
_.intersection(first, second)
first.filter(it => second.includes(it))