๋ฐ์ํ
Problem Description
๋ฌธ์์ด my_string๊ณผ ์ ์ n์ด ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, my_string์ ๋ค์ด์๋ ๊ฐ ๋ฌธ์๋ฅผ n๋งํผ ๋ฐ๋ณตํ ๋ฌธ์์ด์ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด๋ณด์ธ์.
Restrictions
- 2 ≤ my_string ๊ธธ์ด ≤ 5
- 2 ≤ n ≤ 10
- "my_string"์ ์์ด ๋์๋ฌธ์๋ก ์ด๋ฃจ์ด์ ธ ์์ต๋๋ค.
Input/Output Example
- ์ ์ถ๋ ฅ ์ #1 "hello"์ ๊ฐ ๋ฌธ์๋ฅผ ์ธ ๋ฒ์ฉ ๋ฐ๋ณตํ "hhheeellllllooo"๋ฅผ return ํฉ๋๋ค.
My solution
function solution(my_string, n) {
return (my_string.split("").map((x) => x.repeat(n))).join('')
}
Another solutions
function solution(my_string, n) {
var answer = [...my_string].map(v => v.repeat(n)).join("");
return answer;
}
๊ตฌ์กฐ๋ถํด ๊ธฐ์ตํ๊ธฐ!
https://school.programmers.co.kr/learn/courses/30/lessons/120825
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/join
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
๋ฐ์ํ
'Problem Solution > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ํผ์ ๋๋ ๋จน๊ธฐ (1) (0) | 2023.09.06 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ์ผ๊ฐํ์ ์์ฑ์กฐ๊ฑด (1) (0) | 2023.09.06 |
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ํน์ ๋ฌธ์ ์ ๊ฑฐํ๊ธฐ (0) | 2023.09.05 |
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ๋ฌธ์์ด์์ ๋ฌธ์์ด (0) | 2023.09.05 |
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ์๋ฆฟ์ ๋ํ๊ธฐ (0) | 2023.09.05 |