Condition to check if the length of the array is odd
if ( ( n & 1 ) != 0 ) { left = a [ Math . floor ( n / 2 ) ] ; right = b [ Math . floor ( n / 2 ) ] ; ans = right - left + 1 ; } else { left = ( a [ Math . floor ( n / 2 ) ] + a [ Math . floor ( n / 2 ) - 1 ] ) ; right = ( b [ Math . floor ( n / 2 ) ] + b [ Math . floor ( n / 2 ) - 1 ] ) ; ans = right - left + 1 ; } document . write ( ans ) ; }