Subtract sum from second array elements one by one and check it 's present in array first  or not
for ( let j = 0 ; j < m ; j ++ ) if ( s . has ( x - arr2 [ j ] ) ) document . write ( x - arr2 [ j ] + " " + arr2 [ j ] + " " ) ; }