- Notifications
You must be signed in to change notification settings - Fork5
isDisjoint
Subhajit Sahu edited this pageMay 3, 2023 ·25 revisions
Examine if arrays have no value in common.
Similar:isUnique,isDisjoint,intersection.
functionisDisjoint(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²).
constxarray=require('extra-array');varx=[1,2,3,4];xarray.isDisjoint(x,[2,5]);// → falsexarray.isDisjoint(x,[-2,-5]);// → truexarray.isDisjoint(x,[-2,-5],(a,b)=>Math.abs(a)-Math.abs(b));// → falsexarray.isDisjoint(x,[-2,-5],null,v=>Math.abs(v));// → false