๐Ÿ”†[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ฐ๋„๊ธฐ

๋ฆฌ๋น—ยท2023๋…„ 10์›” 19์ผ
0

JavaScript ์ฝ”๋”ฉํ…Œ์ŠคํŠธ

๋ชฉ๋ก ๋ณด๊ธฐ
4/7
post-custom-banner

๐Ÿ“Œ ๋‚ด ํ’€์ด

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;
}

์ฐธ๊ณ ์ž๋ฃŒ

profile
์–ด์ œ๋ณด๋‹ค ๋‚˜์€ ์˜ค๋Š˜์„ ์œ„ํ•ด
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€