Skip to content

intersection

Subhajit Sahu edited this page Dec 28, 2022 · 16 revisions

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]];
var y = [['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

Clone this wiki locally