1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
function solution(a, b) { const days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; const dow = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']; let eachFirstDow = [5]; let tmp; for (let i = 1; i < a; i++) { tmp = days[i - 1] % 7; console.log(i + 1, dow[(eachFirstDow[i - 1] + tmp) % 7]); eachFirstDow[i] = (eachFirstDow[i - 1] + tmp) % 7; } eachFirstDow.forEach((item) => { console.log(dow[item]); }); tmp = (b - 1) % 7; return dow[(eachFirstDow[a - 1] + tmp) % 7]; } result = solution(10, 1); result = solution(5, 24);
|