프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
CODECATA_Algorithms/프로그래머스/0/181950. 문자열 반복해서 출력하기 at main · Jacob-moon/CODECATA_Algori
Contribute to Jacob-moon/CODECATA_Algorithms development by creating an account on GitHub.
github.com
주요 개념 : Sring.prototype.repeat()
str.repeat(count);
count
String.prototype.repeat() - JavaScript | MDN
repeat() 메서드는 문자열을 주어진 횟수만큼 반복해 붙인 새로운 문자열을 반환합니다.
developer.mozilla.org
문자열을 반복할 횟수. 0과 양의 무한대 사이의 정수([0, +∞)).반환값
반환값
현재 문자열을 주어진 횟수만큼 반복해 붙인 새로운 문자열.
예외
- RangeError: 반복 횟수는 양의 정수여야 함.
- RangeError: 반복 횟수는 무한대보다 작아야 하며, 최대 문자열 크기를 넘어선 안됨.
예
"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)
'Daily Logs > Algorithm Practice' 카테고리의 다른 글
[level 0] 덧셈식 출력하기 (0) | 2025.05.18 |
---|---|
[level 0] 특수문자 출력하기 (1) | 2025.05.18 |
[level 0] 대소문자 바꿔서 출력하기 (1) | 2025.05.17 |
[level 0] a와 b 출력하기 (0) | 2025.05.17 |
[level 0] 문자열 출력하기 (0) | 2025.05.16 |