whatisthis?

๋ฐฑ์ค€ 2438 javascript (node.js) ํ’€์ด ๋ณธ๋ฌธ

ALGORITHM/BOJ (Node.js)

๋ฐฑ์ค€ 2438 javascript (node.js) ํ’€์ด

thisisyjin 2021. 12. 11. 22:20

for๋ฌธ - (9)

 

 


 

๐Ÿ’ก๋ฌธ์ œ

์ฒซ์งธ ์ค„์—๋Š” ๋ณ„ 1๊ฐœ, ๋‘˜์งธ ์ค„์—๋Š” ๋ณ„ 2๊ฐœ, N๋ฒˆ์งธ ์ค„์—๋Š” ๋ณ„ N๊ฐœ๋ฅผ ์ฐ๋Š” ๋ฌธ์ œ

๐Ÿ“์ž…๋ ฅ

์ฒซ์งธ ์ค„์— N(1 ≤ N ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค.

๐Ÿ“ˆ์ถœ๋ ฅ

์ฒซ์งธ ์ค„๋ถ€ํ„ฐ N๋ฒˆ์งธ ์ค„๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ ๋ณ„์„ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ

5

์˜ˆ์ œ ์ถœ๋ ฅ

*
**
***
****
*****

 


< ์ฝ”๋“œ >

let input = Number(require('fs').readFileSync('/dev/stdin'));
let ans ='';

for(let i=1; i<=input; i++) {
   ans += "*".repeat(i) + "\n"
}
console.log(ans);

 

 

 

.repeat()

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

 

Syntax

str.repeat(count);

** count๋Š” 0์ด์ƒ ์–‘์˜ ์ •์ˆ˜์—ฌ์•ผ ํ•œ๋‹ค.