Pair with given product | Set 1 ( Find if any pair exists ) | Returns true if there is a pair in arr [ 0. . n - 1 ] with product equal to x . ; Create an empty set and insert first element leto it ; Traverse remaining elements ; 0 case must be handles explicitly as x % 0 is undefined ; x / arr [ i ] exists in hash , then we found a pair ; Insert arr [ i ] ; Driver program
function isProduct ( arr , n , x ) { let hset = new Set ( ) ; if ( n < 2 ) return false ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) { if ( x == 0 ) return true ; else continue ; } if ( x % arr [ i ] == 0 ) { if ( hset . has ( x / arr [ i ] ) ) return true ; hset . add ( arr [ i ] ) ; } } return false ; } let arr = [ 10 , 20 , 9 , 40 ] ; let x = 400 ; let n = arr . length ; if ( isProduct ( arr , arr . length , x ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; x = 190 ; if ( isProduct ( arr , arr . length , x ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;