text: Make all array elements even by replacing any pair of array elements with their sum | Function to find the minimum number of replacements required to make all array elements even ; Stores the count of odd elements ; Traverse the array ; Increase count of odd elements ; Store number of replacements required ; Two extra moves will be required to make the last odd element even ; Print the minimum replacements ; Driver Code ; Function call
code: function minMoves ( arr , N ) { var odd_element_cnt = 0 ; var i ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 != 0 ) { odd_element_cnt ++ ; } } var moves = Math . floor ( ( odd_element_cnt ) / 2 ) ; if ( odd_element_cnt % 2 != 0 ) moves += 2 ; document . write ( moves ) ; } var arr = [ 5 , 6 , 3 , 7 , 20 ] ; N = arr . length ; minMoves ( arr , N ) ;