Given two unsorted arrays , find all pairs whose sum is x | Function to find all pairs in both arrays whose sum is equal to given value x ; Insert all elements of first array in a hash ; Subtract sum from second array elements one by one and check it 's present in array first  or not ; Driver code
function findPairs ( arr1 , arr2 , n , m , x ) { let s = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) s . set ( arr1 [ i ] , 0 ) ; for ( let j = 0 ; j < m ; j ++ ) if ( s . has ( x - arr2 [ j ] ) ) document . write ( x - arr2 [ j ] + " " + arr2 [ j ] + " " ) ; } let arr1 = [ 1 , 0 , - 4 , 7 , 6 , 4 ] ; let arr2 = [ 0 , 2 , 4 , - 3 , 2 , 1 ] ; let x = 8 ; findPairs ( arr1 , arr2 , arr1 . length , arr2 . length , x ) ;