๐ ๋ด ํ์ด
1. if ๋ฌธ์ ํ์ฉํ ํ์ด
- ์ด์ ์กฐ๊ฑด๋ฌธ์ ํตํด 0 < angle <= 90๊ฒฝ์ฐ๊ฐ ์ฌ๋ผ์ก์ผ๋ฏ๋ก, ๋ฌต์์ ์ผ๋ก 90 < angle์ ์๋ฏธ
- ๋ฐ๋ผ์, 90 < angle์ ์๋ต ๊ฐ๋ฅ
function solution(angle) {
var answer = 0;
if(0 < angle && angle < 90){
answer = 1;
}else if(angle === 90){
answer = 2;
}else if(90 < angle && angle < 180){
answer = 3;
}else{
answer = 4;
}
return answer;
}
๐ ๋ค๋ฅธ ํ์ด
1. if๋ฌธ์ ํ์ฉํ ํ์ด
function solution(angle) {
if(angle && angle < 90){
return 1;
}else if(angle === 90){
return 2;
}else if(angle < 180){
answer = 3;
}else{
answer = 4;
}
return answer;
}
2. Array fliter๋ฅผ ์ฌ์ฉํ ํ์ด(์ดํด๋ชปํจ...)
function solution(angle) {
return [0, 90, 91, 180].filter(x => angle>=x).length;
}
3. ์ผํญ ์ฐ์ฐ์๋ฅผ ํ์ฉํ ํ์ด(์ข์ ์ฝ๋์ธ์ง๋ ๋ชจ๋ฅด๊ฒ ์)
function solution(angle) {
return angle < 90 ? 1 : angle === 90 ? 2 : angle < 180 ? 3 : 4;
}
์ฐธ๊ณ ์๋ฃ