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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] l๋กœ ๋งŒ๋“ค๊ธฐ ๋ณธ๋ฌธ

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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] l๋กœ ๋งŒ๋“ค๊ธฐ

Eun_zii 2024. 3. 15. 14:51

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

- l๋กœ ๋งŒ๋“ค๊ธฐ

 

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

  • ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด myString์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์•ŒํŒŒ๋ฒณ ์ˆœ์„œ์—์„œ "l"๋ณด๋‹ค ์•ž์„œ๋Š” ๋ชจ๋“  ๋ฌธ์ž๋ฅผ "l"๋กœ ๋ฐ”๊พผ ๋ฌธ์ž์—ด์„ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”.

 

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

  • 1 ≤ myString ≤ 100,000
    • myString์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.

 

๐Ÿ’š ํ’€์ด

function solution(myString) {
    let answer = "";
    for ( let i = 0; i < myString.length; i++ ) {
       if ( myString[i] < "l") {
           answer += "l"
       } else {
           answer += myString[i]
       }
    }
    return answer
}

 

โœ… 

์ƒˆ ๋นˆ๋ฐฐ์—ด์ธ answer๋ฅผ ์„ ์–ธํ•ด์ค€ํ›„, 

myString์˜ [i] ๊ฐ€ "l" ๋ณด๋‹ค ์ž‘์œผ๋ฉด answer์— "l"์„ ์ถ”๊ฐ€ํ•ด์ฃผ๊ณ ,

"l" ์ดˆ๊ณผ๋ผ๋ฉด ์›๋ž˜ myString์˜ [i]๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ์ค€ํ›„ retrun ํ•ด์ค€๋‹ค. 

728x90