๐Ÿค ์€์ง€log ๐Ÿค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด ๋ณธ๋ฌธ

๐ŸŒˆ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด

Eun_zii 2024. 4. 24. 15:53

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0

- ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด

 

๐Ÿ’š ๋ฌธ์ œ์„ค๋ช…

 

๐Ÿ’š ์ œํ•œ์กฐ๊ฑด

  • 0 < rsp์˜ ๊ธธ์ด ≤ 100
  • rsp์™€ ๊ธธ์ด๊ฐ€ ๊ฐ™์€ ๋ฌธ์ž์—ด์„ return ํ•ฉ๋‹ˆ๋‹ค.
  • rsp๋Š” ์ˆซ์ž 0, 2, 5๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ’š ํ’€์ด

function solution(rsp) {
    let answer = ''
    for (let game of rsp) {
        if (game === "2") {
            answer += "0"
        } else if (game === "0") {
            answer += "5"
        } else if (game === "5") {
            answer += "2"
        }
    }
    return answer;
}

 

โœ… 

for .. of ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ rsp์˜ ๊ฐ ํ˜„์žฌ ๋ฌธ์ž(game)๋ฅผ ๋ฐ˜๋ณตํ•ด์ฃผ๊ณ , 

๋ฌธ์ž๊ฐ€ "2"๋ผ๋ฉด "0"์„ , "0"์ด๋ผ๋ฉด "5"๋ฅผ, "5"๋ผ๋ฉด "2"๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ๋ฅผ ๋งŒ๋“ค์–ด

answer์— ๋”ํ•ด์ค€ํ›„ return ํ•ด์ค€๋‹ค.

728x90