๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

ํ”„์—” ๊ณต๋ถ€/๐Ÿซง ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ณต๋ถ€

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] [level.0] ์ง๊ฐ์‚ผ๊ฐํ˜• ์ถœ๋ ฅํ•˜๊ธฐ || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ

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

let input = [3];

rl.on('line', function (line) {
    input = line.split(' ');
}).on('close', function () {
    const star = Number(input[0]);
    for (let i = 1; i <= star; i++) {
        console.log('*'.repeat(i));
    }
});

์ฒจ์— ์ฃผ์–ด์ง„ ์ฝ”๋“œ ๋ณด๊ณ  ์ข€ ๋‹นํ™ฉํ–ˆ๋Š”๋ฐ, 

๋‹ค์Œ์— ์ฐพ์•„๋ณธ ํ›„ ๋‹ค์‹œ ๋ณด๋‹ˆ ์–ด๋””์— ๋ฌธ์ œ๋ฅผ ํ’€๋ฉด ๋ ์ง€ ๋ณด์˜€๋‹ค.

์ฐพ์œผ๋ฉด์„œ repeat ์ด๋ž€ String ํ•จ์ˆ˜์— ๋Œ€ํ•ด์„œ๋„ ์•Œ๊ฒŒ ๋๋‹ค. 

 

str.repeat(count);

str : ์–ด๋–ค ๋ฌธ์ž๋ฅผ

repeat ๋ฐ˜๋ณตํ•œ๋‹ค

count : ๋ช‡๋ฒˆ

 

 

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/repeat

 

String.prototype.repeat() - JavaScript | MDN

repeat() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด์„ ์ฃผ์–ด์ง„ ํšŸ์ˆ˜๋งŒํผ ๋ฐ˜๋ณตํ•ด ๋ถ™์ธ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

developer.mozilla.org

 

728x90
๋ฐ˜์‘ํ˜•