Find any two pairs ( a , b ) and ( c , d ) such that a d | Javascript implementation to sort the array of points by its distance from the given point ; Function to find two pairs ( a , b ) and ( c , d ) such that a < c and b > d ; If no such pair is found ; Driver code
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function findPair ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { let a = arr [ i ] . first , b = arr [ i ] . second ; for ( let j = i + 1 ; j < N ; j ++ ) { let c = arr [ j ] . first , d = arr [ j ] . second ; if ( a < c && b > d ) { document . write ( " " + a + " " + b + " " + c + " " + d + " " ) ; return ; } } } document . write ( " " ) ; } let arr = [ new pair ( 3 , 7 ) , new pair ( 21 , 23 ) , new pair ( 4 , 13 ) , new pair ( 1 , 2 ) , new pair ( 7 , - 1 ) ] ; findPair ( arr , 5 ) ;