-
Notifications
You must be signed in to change notification settings - Fork 5
intersection
Subhajit Sahu edited this page May 19, 2020
·
26 revisions
Gives values present in both arrays. 🏃 📼 📦 🌔
array.intersection(x, y, [fn]);
// x: an array
// y: another array
// fn: compare function (a, b)
⏱️ Compare function => O(n²).
const array = require('extra-array');
var x = [1, 2, 3, 4];
var y = [2, 3, 5];
array.intersection(x, y);
// [ 2, 3 ]
var y = [-2, -3, -5];
array.intersection(x, y, (a, b) => Math.abs(a) - Math.abs(b));
// [ 2, 3 ]
array.intersection(x, y, null, v => Math.abs(v));
// [ 2, 3 ]