If there are even elements , then there are two medians . We consider the best of two as answer .
if ( ( n * m ) % 2 == 0 ) { let median2 = arr [ parseInt ( ( n * m ) / 2 , 10 ) ] ; let minOperations2 = 0 ; for ( let i = 0 ; i < n * m ; ++ i ) minOperations2 += parseInt ( Math . abs ( arr [ i ] - median2 ) / k , 10 ) ; minOperations = Math . min ( minOperations , minOperations2 ) ; }