Count Odd Numbers in an Interval Range

EasyMath

Solution

export function countOdds(low: number, high: number): number {
  if (low % 2 === 1 || high % 2 === 1) {
    return Math.ceil((high - low + 1) / 2);
  }
  return (high - low) / 2;
}