-
Notifications
You must be signed in to change notification settings - Fork 5
isDisjoint
Subhajit Sahu edited this page Nov 20, 2022
·
25 revisions
Check if arrays have no value in common.
Similar: isUnique, isDisjoint, intersection.
function isDisjoint(x, y, fc, fm)
// x: an array
// y: another array
// fc: compare function (a, b)
// fm: map function (v, i, x)
⏱️ Compare function => O(n²).
const array = require('extra-array');
var x = [1, 2, 3, 4];
array.isDisjoint(x, [2, 5]);
// → false
array.isDisjoint(x, [-2, -5]);
// → true
array.isDisjoint(x, [-2, -5], (a, b) => Math.abs(a) - Math.abs(b));
// → false
array.isDisjoint(x, [-2, -5], null, v => Math.abs(v));
// → false