Skip to content

intersection

Subhajit Sahu edited this page May 11, 2020 · 26 revisions

Gives values present in both iterables. 🏃 📼 📦 🌔 📒

Alternatives: compare, map.

iterable.intersection(x, y, [fn]);
// x:  an iterable
// y:  another iterable
// fn: compare function (a, b)
const iterable = require('extra-iterable');

var x = [1, 2, 3, 4];
[...iterable.intersection(x, [2, 3, 5])];
// [ 2, 3 ]

[...iterable.intersection(x, [-2, -3, -5], (a, b) => Math.abs(a) - Math.abs(b))];
// [ 2, 3 ]

references

Clone this wiki locally