index.tsx322 chars20 lines
The isLeapYear
function takes a year
as its parameter and returns 0 if it is a leap year, and 1 if it is not.
The function works by first checking if the year is divisible by 4. If it is not, the function will immediately return 1, indicating that it is not a leap year.
If the year is divisible by 4, the function will then check if it is also divisible by 100. If it is, the function will check if it is also divisible by 400. If it is, the function will return 0, indicating that it is a leap year. If it is not divisible by 400, then the function will return 1, indicating that it is not a leap year.
If the year is divisible by 4 but not by 100, the function will return 0, indicating that it is a leap year. This is because any year that is divisible by 4 but not by 100 is a leap year, as long as it is not also divisible by 400.
The final console log statements show how to use the function.
gistlibby LogSnag