Programmers

[프로그래머스][JS] 문자열 반복해서 출력하기

winter17 2023. 5. 11. 22:16

https://school.programmers.co.kr/learn/courses/30/lessons/181950

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

풀이 과정

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = line.split(' ');
}).on('close', function () {
    str = input[0];
    n = Number(input[1]);
    console.log(str.repeat(n)) // << 이 부분
});

자바스크립트에서는 문자열을 해당 숫자만큼 곱할 때 repeat메서드를 사용한다


리뷰

오랜만에 알고리즘 푸니까 쉬운 메서드도 떠오르지 않아서 검색을 했다..