DEV Community

Discussion on: Creating a JavaScript Function to Calculate Whether It's a Leap Year

craigewert profile image

Very clean. But do the 3 parts in the opposite order.

Assuming you get years randomly, most will be not %4, so handle those first.
Similarly, most %4 years will be not %100, so those are next.

just in case the price of 2 extra "if"s is going to break you.