Test name | Executions per second |
---|---|
Lodash | 7723.7 Ops/sec |
Set & Filter | 13989.5 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var arr1 = [];
for(let i = 0; i < 100; i++) {
arr1.push('' + i);
}
var arr2 = [];
for(let i = 49; i >= 0; i--) {
arr2.push('' + i);
}
const notInArr1 = _.difference(arr2, arr1)
const notInArr2 = _.difference(arr1, arr2)
const notInArr1 = arr2.filter(value => !arr1.some(v => v === value));
const notInArr2 = arr1.filter(value => !arr2.some(v => v === value));