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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๊ผฌ๋ฆฌ ๋ฌธ์ž์—ด ๋ณธ๋ฌธ

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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๊ผฌ๋ฆฌ ๋ฌธ์ž์—ด

Eun_zii 2024. 3. 27. 13:14

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

- ๊ผฌ๋ฆฌ ๋ฌธ์ž์—ด 

 

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

  • ๋ฌธ์ž์—ด๋“ค์ด ๋‹ด๊ธด ๋ฆฌ์ŠคํŠธ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋ชจ๋“  ๋ฌธ์ž์—ด๋“ค์„ ์ˆœ์„œ๋Œ€๋กœ ํ•ฉ์นœ ๋ฌธ์ž์—ด์„ ๊ผฌ๋ฆฌ ๋ฌธ์ž์—ด์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๊ผฌ๋ฆฌ ๋ฌธ์ž์—ด์„ ๋งŒ๋“ค ๋•Œ ํŠน์ • ๋ฌธ์ž์—ด์„ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์€ ์ œ์™ธ์‹œํ‚ค๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ ["abc", "def", "ghi"]๊ฐ€ ์žˆ๊ณ  ๋ฌธ์ž์—ด "ef"๋ฅผ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์€ ์ œ์™ธํ•˜๊ณ  ๊ผฌ๋ฆฌ ๋ฌธ์ž์—ด์„ ๋งŒ๋“ค๋ฉด "abcghi"๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
  • ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ str_list์™€ ์ œ์™ธํ•˜๋ ค๋Š” ๋ฌธ์ž์—ด ex๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, str_list์—์„œ ex๋ฅผ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์„ ์ œ์™ธํ•˜๊ณ  ๋งŒ๋“  ๊ผฌ๋ฆฌ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

 

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

  • 2 ≤ str_list์˜ ๊ธธ์ด ≤ 10
  • 1 ≤ str_list์˜ ์›์†Œ์˜ ๊ธธ์ด ≤ 10
  • 1 ≤ ex์˜ ๊ธธ์ด ≤ 5

๐Ÿ’š ํ’€์ด

function solution(str_list, ex) {
    const answer = [];
    for ( let i = 0; i < str_list.length; i++ ) {
       if(!str_list[i].includes(ex)) {
           answer.push(str_list[i])
       }
    }
    return answer.join("");
}

 

โœ…

๋นˆ ๊ฐ’์œผ๋กœ ์ดˆ๊ธฐํ™”๋œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ด์ค€ํ›„, ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ex๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์—๋งŒ answer์— ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

join( ) ๋ฉ”์„œ๋“œ๋กœ ๋ชจ๋“  ๋ฌธ์ž์—ด์„ ์ด์–ด๋ถ™์—ฌ return ํ•ด์ค€๋‹ค.

728x90