Зачем так сложно? Тебе достаточно посчитать количество дней с начала отсчёта и получить остаток от деления на 7.
(() => {
const DAYS_IN_MONTH = 30;
const DAYS_IN_YEAR = DAYS_IN_MONTH * 12;
const LEAP_YEAR_BONUS_DAYS = 1;
const DAYS_OF_WEEK = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const getDayOfWeek = (year, month, day) => {
let daysCount = (year - 1) * DAYS_IN_YEAR + (month - 1) * DAYS_IN_MONTH + day;
daysCount += getAllLeapYearBonusDays(month > 2 ? year : year - 1);
return DAYS_OF_WEEK[daysCount % 7];
};
const getAllLeapYearBonusDays = (year) => (~~(year / 5) - ~~(year / 100) + ~~(year / 500)) * LEAP_YEAR_BONUS_DAYS;
return getDayOfWeek(1001, 8, 24); // Tuesday
return getDayOfWeek(1, 8, 24); // Tuesday
})()