Sort first half in ascending and second half in descending order | 1 | function to print half of the array in ascending order and the other half in descending order ; sorting the array ; printing first half in ascending order ; printing second half in descending order ; Driver code
function printOrder ( arr , n ) { arr . sort ( ) ; for ( i = 0 ; i < parseInt ( n / 2 ) ; i ++ ) { document . write ( arr [ i ] + " " ) ; } for ( j = n - 1 ; j >= parseInt ( n / 2 ) ; j -- ) { document . write ( arr [ j ] + " " ) ; } } var arr = [ 5 , 4 , 6 , 2 , 1 , 3 , 8 , - 1 ] ; var n = arr . length ; printOrder ( arr , n ) ;