How to check if two given sets are disjoint ? | Returns true if set1 [ ] and set2 [ ] are disjoint , else false ; Take every element of set1 [ ] and search it in set2 ; If no element of set1 is present in set2 ; Driver program to test above function
function aredisjoint ( set1 , set2 ) { for ( let i = 0 ; i < set1 . length ; i ++ ) { for ( let j = 0 ; j < set2 . length ; j ++ ) { if ( set1 [ i ] == set2 [ j ] ) return false ; } } return true ; } let set1 = [ 12 , 34 , 11 , 9 , 3 ] ; let set2 = [ 7 , 2 , 1 , 5 ] ; result = aredisjoint ( set1 , set2 ) ; if ( result ) document . write ( " " ) ; else document . write ( " " ) ;