๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

ํ”„์—” ๊ณต๋ถ€/๐Ÿซง ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ณต๋ถ€

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ์ ์˜ ์œ„์น˜ ๊ตฌํ•˜๊ธฐ|| ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ

728x90
function solution(dot) {
    var answer = 0;
    
    if (dot[0] > 0) {
        answer = dot[1] > 0 ? 1 : 4;
    } else {
        answer = dot[1] > 0 ? 2 : 3;
    }
    
    return answer;
}

์š”๊ฑด if ๋ฌธ์œผ๋กœ ํ’€์–ด์ผ์„ ๋•Œ dot[0] ์ด ์–‘์ˆ˜์ธ์ง€ ์Œ์ˆ˜์ธ์ง€์— ๋”ฐ๋ผ ๋‚˜๋ˆ„๊ณ , 

๊ทธ ํ›„์— dot[1] ๊ฐ’์ด ์–‘์ˆ˜๋ƒ ์Œ์ˆ˜๋ƒ์— ๋”ฐ๋ผ answer์— ๊ฐ’์„ ๋„ฃ์–ด์ฃผ๋Š” ํ˜•์‹์œผ๋กœ ๊ตฌ์„ฑํ–ˆ๋‹ค.

 

๊ทผ๋ฐ ๊ถ๊ธˆํ–ˆ๋˜๊ฒŒ ์ด์ค‘์œผ๋กœ ์‚ผํ•ญ์—ฐ์‚ฐ์ž๋ฅผ ์“ธ ์ˆ˜ ์žˆ์„๊นŒ ์˜€๋‹ค.

function solution(dot) {
    var answer = 0;

    dot[0] > 0 ? (answer = dot[1] > 0 ? 1 : 4) : (answer = dot[1] > 0 ? 2 : 3);
   
    return answer;
}

์ž˜ ๋˜๋Š”๊ฑธ ํ™•์ธํ–ˆ๊ณ , 

ํ•œ ์ค„๋กœ๋„ ํ‘œํ˜„์ด ๊ฐ€๋Šฅํ•˜๋‹ค! โ˜˜๏ธ

728x90
๋ฐ˜์‘ํ˜•