Test name | Executions per second |
---|---|
Lodash | 7676334.0 Ops/sec |
Set | 4519926.5 Ops/sec |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js"></script>
var a = [1, 2, 3, 4, 5]
var b = [3, 4, 5, 6, 7]
var c = _.difference(a, b)
const set1 = new Set(a);
const set2 = new Set(b);
const unionSet = [a, b];
const uniqueNumbers = unionSet.filter(
(num) => !(set1.has(num) && set2.has(num))
);