Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.