Find the final sequence of the array after performing given operations | javascript implementation of the approach ; Driver code
function solve ( arr , n ) { var b = Array ( n ) . fill ( 0 ) ; var p = 0 ; for ( i = n - 1 ; i >= 0 ; i -- ) { b [ p ] = arr [ i -- ] ; if ( i >= 0 ) b [ n - 1 - p ] = arr [ i ] ; p ++ ; } return b ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; var b = solve ( arr , n ) ; document . write ( " " + b . toString ( ) + " " ) ;