Drill

ProblemsTypeScript › dates

Is it a leap year

easydatesTypeScript

A billing schedule needs to know whether February has 29 days.

isLeapYear(year: int) → bool

Solve it in the editor →

Where you start

function isLeapYear(year: number): boolean {
  
}

Worked examples

CallResult
isLeapYear(2024)true
isLeapYear(2023)false
isLeapYear(1900)false
isLeapYear(2000)true

Hint

The 400 rule wins over the 100 rule, which wins over the 4 rule. Order the checks accordingly.

Reference solution in TypeScript
function isLeapYear(year: number): boolean {
  if (year < 1) return false;
  if (year % 400 === 0) return true;
  if (year % 100 === 0) return false;
  return year % 4 === 0;
}

The same problem in another language

More dates problems in TypeScript