next-intersection
Simple intersection implement.
installation
npm install -S @jswork/next-intersection
usage
import '@jswork/next-intersection';
const a1 = [1, 2, 3];
const a2 = [2, 3, 4];
nx.intersection(a1, a2)
// [2, 3]
const a1 = [
{ id: 1, value: 'aa' },
{ id: 2, value: 'bb' },
{ id: 3, value: 'cc' }
];
const a2 = [
{ id: 3, value: 'cc' },
{ id: 4, value: 'dd' }
];
const ids = a2.map(item => item.id);
const res = nx.intersection(a1, a2, (_, value) => {
return ids.includes(value.id);
});
// [ { id: 3, value: 'cc' } ]
resources
license
Code released under the MIT license.