Skip to content

intersection

wolfram77 edited this page Mar 27, 2020 · 26 revisions

Gives values present in both arrays.

Alternatives: compare, map.

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

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

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

references

Clone this wiki locally