문제 설명
문자열 my_string과 정수 n이 매개변수로 주어질 때, my_string에 들어있는 각 문자를 n만큼 반복한 문자열을 return 하도록 solution 함수를 완성해보세요.
function solution(my_string, n) {
my_string.repeat(n) // hellohellohello 출력
}
하지만 문제에서 요구하는 것은 문자열 전체를 n만큼 반복이 아니라 문자열 하나하나를 n만큼 반복해야하는 것!!
hellohellohello (x)
hhheeellllllooo (o)
split
을 써서 문자열을 배열로 만들어줌const arr = my_string.split('') // ['h', 'e', 'l', 'l', 'o']
const mapArr = arr.map((word)=>{return word.repeat(n)})
mapArr.join('')
function solution(my_string, n) {
const arr = my_string.split('')
const mapArr = arr.map((word)=>{return word.repeat(n)})
return mapArr.join('')
}