Maximize the division result of Array using given operations | Function to find the max result ; Sort the array in descending order ; Loop to divide in this order arr [ 0 ] / ( arr [ 1 ] / arr [ 2 ] / ... . arr [ n - 2 ] / arr [ n - 1 ] ) ; Return the final result ; Driver Code
function maxDivision ( arr , n ) { arr . sort ( ( a , b ) => b - a ) ; let mxdiv = arr [ 1 ] ; for ( let i = 2 ; i < n ; ++ i ) mxdiv = mxdiv / arr [ i ] ; return arr [ 0 ] / mxdiv ; } let arr = [ 100 , 1000 , 10 , 2 ] ; let n = arr . length ; document . write ( maxDivision ( arr , n ) ) ;