프로그래머스 풀이/level0

[Programmers] level 0) 문제 '문자 반복 출력하기' 풀이

진기명기 2023. 2. 26. 14:35
🫠 Programmers (level 0) 
👉🏻 문제 14번 (문자 반복 출력하기) : 문자열 n만큼 반복하기

 

 

 


function solution(my_string, n){
  // 문자열을 배열로 변경하기
  let res1 = [...my_string]

  // map을 사용하여 요소를 순회하고, for문으로 3번 반복한 값을 result에 push
  let result = []
  res1.map((item) => {
    for(let i = 0; i < n; i++){
      result.push(item)
    }
  })

  // 문자열로 다시 변경하여 반환
  return result.join('')
  
  }

 

✅ 확인할 점

💡반복하는 함수로 repeat()이 있었다.. 까먹지 말자!!