Rotate all odd numbers right and all even numbers left in an Array of 1 to N | function to left rotate ; function to right rotate ; Function to rotate the array ; Driver code
function left_rotate ( arr ) { let last = arr [ 1 ] ; for ( let i = 3 ; i < 6 ; i = i + 2 ) { arr [ i - 2 ] = arr [ i ] ; } arr [ 6 - 1 ] = last ; } function right_rotate ( arr ) { let start = arr [ 6 - 2 ] ; for ( let i = 6 - 4 ; i >= 0 ; i = i - 2 ) { arr [ i + 2 ] = arr [ i ] ; } arr [ 0 ] = start ; } function rotate ( arr ) { left_rotate ( arr ) ; right_rotate ( arr ) ; for ( let i = 0 ; i < 6 ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; rotate ( arr ) ;