Function to calculate value of X
function valueofX ( ar , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum = sum + ar [ i ] ; } if ( sum % n == 0 ) { return Math . floor ( sum / n ) ; } else { let A = Math . floor ( sum / n ) , B = Math . floor ( sum / n + 1 ) ; let ValueA = 0 , ValueB = 0 ;