Given an array of pairs , find all symmetric pairs in it | Print all pairs that have a symmetric counterpart ; Creates an empty hashMap hM ; Traverse through the given array ; First and second elements of current pair ; Look for second element of this pair in hash ; If found and value in hash matches with first element of this pair , we found symmetry ; Else put sec element of this pair in hash ; Driver method
function findSymPairs ( arr ) { let hM = new Map ( ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { let first = arr [ i ] [ 0 ] ; let sec = arr [ i ] [ 1 ] ; let val = hM . get ( sec ) ; if ( val != null && val == first ) document . write ( " " + sec + " " + first + " " ) ; else hM . set ( first , sec ) ; } } let arr = new Array ( 5 ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = new Array ( 2 ) ; for ( let j = 0 ; j < 2 ; j ++ ) { arr [ i ] [ j ] = 0 ; } } arr [ 0 ] [ 0 ] = 11 ; arr [ 0 ] [ 1 ] = 20 ; arr [ 1 ] [ 0 ] = 30 ; arr [ 1 ] [ 1 ] = 40 ; arr [ 2 ] [ 0 ] = 5 ; arr [ 2 ] [ 1 ] = 10 ; arr [ 3 ] [ 0 ] = 40 ; arr [ 3 ] [ 1 ] = 30 ; arr [ 4 ] [ 0 ] = 10 ; arr [ 4 ] [ 1 ] = 5 ; findSymPairs ( arr ) ;