Reverse an array without using subtract sign â €˜ | Function to reverse array ; Trick to assign - 1 to a variable ; Reverse array in simple manner ; Swap ith index value with ( n - i - 1 ) th index value ; Drivers code ; print the reversed array
function reversearray ( arr , n ) { let x = parseInt ( - 2147483648 / 2147483647 , 10 ) ; for ( let i = 0 ; i < parseInt ( n / 2 , 10 ) ; i ++ ) { let temp = arr [ i ] ; arr [ i ] = arr [ n + ( x * i ) + x ] ; arr [ n + ( x * i ) + x ] = temp ; } } let arr = [ 5 , 3 , 7 , 2 , 1 , 6 ] ; let n = arr . length ; reversearray ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;