2016년
![](https://velog.velcdn.com/images%2Felena_park%2Fpost%2F0566fba4-02ad-4ffe-b04b-9c41a6f8c023%2F%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%9811-2016.png)
풀이 1
// 2016년 (Date 객체메서드를 이용한 방법)
function solution12(month, date) {
const x = new Date(2016, month - 1, date);
const dates = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
return dates[x.getDay()];
}
console.log(solution12(5, 24)); // "TUE";
풀이 2
// 2016년 (Date 객체메서드를 이용하지 않은 방법으로 풀기)
function solution13(month, date) {
const dates = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
const months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
let startDay = 0;
for (let i = 0; i < month - 1; i++) {
startDay += months[i];
// startDay -= months[month-1]
}
startDay += date;
startDay += dates.indexOf("FRI");
startDay -= 1;
startDay %= dates.length;
return dates[startDay];
}
console.log(solution13(5, 24)); // "TUE";