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

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

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

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ) - ์ž˜๋ผ์„œ ๋ฐฐ์—ด๋กœ ์ €์žฅํ•˜๊ธฐ

eazyseon 2023. 2. 27. 11:20
๋ฐ˜์‘ํ˜•

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

 

 

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

 

 

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

 

function solution(my_str, n) {
  let answer = [];
  let cnt = 0
  while(cnt<my_str.length){
    answer.push(my_str.substr(cnt,n))
    cnt+=n
  }
    return answer;
}

 

substr์ด๋ผ๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ’€์—ˆ๋‹ค.

substr(์‹œ์ž‘์ธ๋ฑ์Šค, ๊ธธ์ด)๋ฅผ ์ฃผ์–ด ์‚ฌ์šฉํ•œ๋‹ค. 

๊ทธ๋Ÿผ ์•„๋ž˜์ฒ˜๋Ÿผ ๋ฌธ์ž์—ด์„ ์ž๋ฅผ ์ˆ˜ ์žˆ๊ณ  ํ•ด๋‹น ๋ฌธ์ž์—ด์„ ๋นˆ ๋ฐฐ์—ด์— push ํ•ด์ฃผ๋ฉด ๋œ๋‹ค! 

my_str.substr(cnt,n) // 'abc1Ad' , 'dfggg4' ,'556b'

 

- ๋ฐฐ์šด ์ 

1.substr (ํ•ญ์ƒ ํ—ท๊ฐˆ๋ฆฌ๋˜ substr,substring,slice ๋น„๊ต ๐Ÿ‘‰ https://eazyseon.tistory.com/20)

๋ฐ˜์‘ํ˜•
Comments