intersection - nodef/extra-lists GitHub Wiki

Obtain entries present in both lists.

Similar: union, intersection, difference, symmetricDifference, isDisjoint.

function intersection(x, y, fc)
// x:  lists
// y:  another lists
// fc: combine function (a, b)
const xlists = require('extra-lists');

var x = ['a', 'b', 'c', 'd'], [1, 2, 3, 4](/nodef/extra-lists/wiki/'a',-'b',-'c',-'d'],-[1,-2,-3,-4);
var y = ['b', 'c', 'e'], [20, 30, 50](/nodef/extra-lists/wiki/'b',-'c',-'e'],-[20,-30,-50);
xlists.intersection(x, y).map(c => [...c]);
// → [ [ 'b', 'c' ], [ 2, 3 ] ]

xlists.intersection(x, y, (a, b) => b).map(c => [...c]);
// → [ [ 'b', 'c' ], [ 20, 30 ] ]

References