Notice
Recent Posts
Recent Comments
Link
ยซ   2025/05   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

eazyseon

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ) - ์˜น์•Œ์ด(1) ๋ณธ๋ฌธ

๐Ÿง์•Œ๊ณ ๋ฆฌ์ฆ˜?์•Œ๊ณ ์‹ถ์Œ!

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ) - ์˜น์•Œ์ด(1)

eazyseon 2023. 3. 12. 09:14
๋ฐ˜์‘ํ˜•

- ๋ฌธ์ œ ์„ค๋ช…

 

-์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฐ˜์‘ํ˜•

- ๋‚˜์˜ ํ’€์ด

function solution(babbling) {
  let answer = 0;
  const arr = ['aya','ye','woo','ma']
  let word = '';
  
  for(let i=0; i<babbling.length; i++){
    //์ธ์ž๊ฐ€ ["aya", "yee", "u", "maa", "wyeoo"]๋ผ๋ฉด
    //word='aya'/'yee'/'u'...์ถœ๋ ฅ
    word = babbling[i]
    //arr๋ฐฐ์—ด์„ ๋ฐ˜๋ณตํ•˜๋ฉฐ
    for(let j=0; j<arr.length; j++){
      //word ์•ˆ์—์„œ arr[j]์— ํ•ด๋‹นํ•˜๋Š” ๋ฌธ์ž์—ด์„ ' '๋กœ ์น˜ํ™˜
      word = word.replaceAll(arr[j],' ')
    }
    //๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•˜๋Š” trim์„ ์ด์šฉ, length๊ฐ€ 0์ด๋ฉด 
    //๋ฐœ์Œ์ด ๊ฐ€๋Šฅํ•œ ๋‹จ์–ด์ด๋ฏ€๋กœ answer++
    if(word.trim().length === 0){
      answer++;
    }
  }
    return answer;
}

 

 

-๋ฐฐ์šด ์  

1.trim ๐Ÿ˜ฎ‍๐Ÿ’จ

๋ฐ˜์‘ํ˜•
Comments