-문자열 my_string
과 정수 n
이 매개변수로 주어질 때, my_string
에 들어있는 각 문자를 n
만큼 반복한 문자열을 return 하도록 solution 함수를 완성해보세요.
my_string
길이 ≤ 5n
≤ 10my_string | n | return |
---|---|---|
"hello" | 3 | "hhheeellllllooo" |
입출력 예 #1
const solution = (my_string, n) => [...my_string].map(a => a.repeat(n)).join("")
str.repeat(count);
count
'abc'.repeat(-1); // RangeError
'abc'.repeat(0); // ''
'abc'.repeat(1); // 'abc'
'abc'.repeat(2); // 'abcabc'
'abc'.repeat(3.5); // 'abcabcabc' (count will be converted to integer)
'abc'.repeat(1/0); // RangeError
({ toString: () => 'abc', repeat: String.prototype.repeat }).repeat(2);
// 'abcabc' (repeat() is a generic method)
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/repeat