Arrange the numbers in the Array as per given inequalities | Function to place the integers in between the inequality signs ; Sort the integers array and set the index of smallest and largest element ; Iterate over the inequalities ; Append the necessary integers per symbol ; Add the final integer ; Return the answer ; Given List of Integers ; Given list of inequalities ; Function Call ; Print the output
function formAnInequality ( integers , inequalities ) { ( integers ) . sort ( function ( a , b ) { return a - b ; } ) ; let lowerIndex = 0 ; let higherIndex = integers . length - 1 ; let sb = " " ; for ( let ch = 0 ; ch < inequalities . length ; ch ++ ) { if ( inequalities [ ch ] == ' ' ) { sb += " " + ( integers [ lowerIndex ++ ] ) + " " + inequalities [ ch ] ; } else { sb += " " + ( integers [ higherIndex -- ] ) + " " + inequalities [ ch ] ; } } sb += " " + ( integers [ lowerIndex ] ) ; return sb ; } let integers = [ 2 , 5 , 1 , 0 ] ; let inequalities = [ ' ' , ' ' , ' ' ] ; let output = formAnInequality ( integers , inequalities ) ; document . write ( output ) ;