🕊 Link

Lv1. 2016 Javascript
https://programmers.co.kr/learn/courses/30/lessons/12901

🧑🏻‍💻 Code(javascript)

function solution(a, b) {
  const week = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
  const target = new Date(2016, a - 1, b);
  return week[target.getDay()];
}

💡 Solution

function solution(a, b) {
  const week = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
  const target = new Date(2016, a - 1, b); // 5-1 >> 4를 넣으면 5월이 세팅
  // const target = new Date(`2016-${a}-${b}`); // String으로 넣을 경우는 -1을 할 필요가 없음
  return week[target.getDay()];
}
const a = 5; // target = 5월
const b = 24;

👨🏻‍💻💭 Self Feedback

programmers 다른 사람의 풀이

// toString으로 하면 요일이 영어로 나온다는 사실.
 function getDayName(a,b){
   return new Date(2016,a-1,b).toString().slice(0,3).toUpperCase();
 }

  • 2021.04.16 - 최초 작성

댓글 환영 질문 환영
by.protect-me

profile
protect me from what i want

0개의 댓글