Greatest number that can be formed from a pair in a given Array | Function to find the greatest number formed from the pairs ; first append Y at the end of X ; then append X at the end of Y ; Now see which of the two formed numbers is greater than other ; Function to find pairs from array ; Iterate through all pairs ; Driver code
function getNumber ( a , b ) { var X = a . toString ( ) ; var Y = b . toString ( ) ; var XY = X + Y ; var YX = Y + X ; return XY > YX ? XY : YX ; } function printMaxPair ( arr , n ) { var largest = - 100000000 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) { var number = parseInt ( getNumber ( arr [ i ] , arr [ j ] ) ) ; largest = Math . max ( largest , number ) ; } document . write ( largest ) ; } var a = [ 23 , 14 , 16 , 25 , 3 , 9 ] ; var n = a . length ; printMaxPair ( a , n ) ;