๋ฌธ์ ๋ด์ฉ
ํ์ด๐๐ปโ๏ธ
function solution(a, b) {
const resultDay = new Date(2016, a - 1, b);
switch (resultDay.getDay()) {
case 0:
return "SUN";
case 1:
return "MON";
case 2:
return "TUE";
case 3:
return "WED";
case 4:
return "THU";
case 5:
return "FRI";
case 6:
return "SAT";
}
}
- switch๋ฅผ ์ด์ฉํด ํ์ด๋ดค๋ค.
- ํด๋นํ๋ ๋ ์ง์ Date๊ฐ์ฒด๋ฅผ ์์ฑํด์ฃผ๊ณ getDay ๋ฉ์๋ ๋ฆฌํด๊ฐ์ ๋ฐ๋ผ ๊ฐ์ ๋ฆฌํดํด์คฌ๋ค.
๋ค๋ฅธ๋ถ ํ์ด
function solution(a, b) {
const days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
const date = new Date(2016, a - 1, b);
return days[date.getDay()];
}
- ๋ฐฐ์ด์ ํญ๋ชฉ๋ค์ ๋ฃ๊ณ getDay๊ฐ ๋ฐํํ๋ ๊ฐ์ days๋ฐฐ์ด์ ์ธ๋ฑ์ค๋ก ํธ์ถํ๋ค.
- ํจ์ฌ๊น๋.. ๋ฐํ ๊ฐ์ด ์ซ์์ผ ๊ฒฝ์ฐ ์ธ๋ฑ์ค ํ์ฉ์ด ๊ฐ๋ฅํ์ง ๊ฒํ ํด๋ณด์.
'์๊ณ ๋ฆฌ์ฆ & ๋ฌธ์ ํ์ด > Programmers-1' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ ์ ์ ๊ณฑ๊ทผ ํ๋ณ (0) | 2022.09.18 |
---|---|
์๋ฆฟ์ ๋ํ๊ธฐ (0) | 2022.09.18 |
์์ ์ํธ (0) | 2022.09.06 |
๋ฌธ์์ด ๋ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ (0) | 2022.09.05 |
์์ฐ (0) | 2022.09.03 |