Last active
February 23, 2019 02:32
-
-
Save robbywashere-zz/9f57636a5531de91c75aa60521663b75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function monthDays(year){ | |
const m = (new Array(12)).fill(1).map((_,x)=>x%2?30:31); | |
if (year % 4) m[1] = 28; | |
else if (year % 100) m[1] = 29; | |
else if (year % 400) m[1] = 28 | |
else m[1] = 28; | |
return m; | |
} | |
function firstSundays(start, end){ | |
let r = 0; | |
let sundays = 0; | |
for (let y = 1900; y < end; y++){ | |
for (let days of monthDays(y)){ | |
r = (days + r) % 7; | |
if (r === 0 && y >= start) sundays++ | |
} | |
} | |
return sundays; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment