Which weekday falls on a given date? Sakamoto's method answers it in one formula. It shifts January and February to the end of the previous year, so the leap day comes last:
const t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
if (m < 3) y -= 1;
const w = (y + ⌊y/4⌋ − ⌊y/100⌋ + ⌊y/400⌋ + t[m−1] + d) % 7; // 0 = Sunday
The table t encodes how far each month's first day is shifted. The /4, /100, /400 terms count leap years under the Gregorian rules.