Find Union and Intersection of two unsorted arrays | Function to find intersection ; when both are equal ; Driver Code ; sort ; Function call
function intersection ( a , b , n , m ) { let i = 0 , j = 0 ; while ( i < n && j < m ) { if ( a [ i ] > b [ j ] ) { j ++ ; } else if ( b [ j ] > a [ i ] ) { i ++ ; } else { document . write ( a [ i ] + " " ) ; i ++ ; j ++ ; } } } let a = [ 1 , 3 , 2 , 3 , 4 , 5 , 5 , 6 ] ; let b = [ 3 , 3 , 5 ] let n = a . length ; let m = b . length ; a . sort ( ) ; b . sort ( ) ; intersection ( a , b , n , m ) ;