Segregate even and odd numbers | Set 3 | JavaScript Implementation of the above approach ; Driver code ; Function call
function arrayEvenAndOdd ( arr , n ) { let a = [ ] ; let ind = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { a [ ind ] = arr [ i ] ; ind ++ ; } } for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 != 0 ) { a [ ind ] = arr [ i ] ; ind ++ ; } } for ( let i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + " " ) ; } document . write ( ' ' ) ; } let arr = [ 1 , 3 , 2 , 4 , 7 , 6 , 9 , 10 ] ; let n = arr . length ; arrayEvenAndOdd ( arr , n ) ;