javaScript 주어질 월과 일에 해당하는 요일 구하기
문제 1월 1일이 금요일일 때 a월 b일의 요일을 구하여라 풀이 function solution(a, b) { const daysInMonth = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; const totalDays = daysInMonth.slice(0, a).reduce((acc, cur) => acc + cur, 0) + b - 1; const dayOfWeek = totalDays % 7; const days = ["FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU"]; return days[dayOfWeek]; } dayInMonth : 각 월의 일 수를 배열로 저장 totalDays : 1월 1일이 금요일이므..
2023. 12. 28.