Make array elements equal with minimum cost | Function to find the minimum cost required to make array elements equal ; Loop to find the count of odd elements ; Driver Code
function makearrayequal ( arr , n ) { var x = 0 ; for ( i = 0 ; i < n ; i ++ ) { x += ( arr [ i ] & 1 ) ; } document . write ( Math . min ( x , n - x ) ) ; } var arr = [ 4 , 3 , 2 , 1 ] ; var n = arr . length ; makearrayequal ( arr , n ) ;