Skip to content

Instantly share code, notes, and snippets.

@robbywashere-zz
Last active February 23, 2019 02:32
Show Gist options
  • Save robbywashere-zz/9f57636a5531de91c75aa60521663b75 to your computer and use it in GitHub Desktop.
Save robbywashere-zz/9f57636a5531de91c75aa60521663b75 to your computer and use it in GitHub Desktop.
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