text: Double the first element and move zero to end | Function For Swaping Two Element Of An Array ; shift all zero to left side of an array ; Maintain last index with positive value ; If Element is non - zero ; swap current index , with lastSeen non - zero ; next element will be last seen non - zero
code: function swap ( A , i , j ) { let temp = A [ i ] ; A [ i ] = A [ j ] ; A [ j ] = temp ; } function shiftAllZeroToLeft ( array , n ) { let lastSeenNonZero = 0 ; for ( let index = 0 ; index < n ; index ++ ) { if ( array [ index ] != 0 ) { swap ( array , array [ index ] , array [ lastSeenNonZero ] ) ; lastSeenNonZero ++ ; } } } }