← Back to challenges

Number of Leap Years

JavaScriptHardnumbersdatesstrings

Instructions

Given a range of years as a string, return the number of leap years there are within the range (inclusive).

Examples

numLeapYears("1980-1984") ➞ 2
// 1980 and 1984 are leapyears.

numLeapYears("2000-2020") ➞ 6

numLeapYears("1600-2000") ➞ 98

Notes

  • Remember that a hyphen separates the years.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.