Count of pairs ( x , y ) in an array such that x < y | Function to return the number of pairs ( x , y ) such that x < y ; To store the number of valid pairs ; If a valid pair is found ; Return the count of valid pairs ; Driver code
function getPairs ( a ) { let count = 0 ; for ( let i = 0 ; i < a . length ; i ++ ) { for ( let j = 0 ; j < a . length ; j ++ ) { if ( a [ i ] < a [ j ] ) count ++ ; } } return count ; } let a = [ 2 , 4 , 3 , 1 ] ; document . write ( getPairs ( a ) ) ;