SMALL

const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const input = +fs.readFileSync(filePath).toString();
star(input);
function star(num) {
for (let i = 0; i < num * 2 - 1; i++) {
let stars = "";
if (i < num) {
for (let j = 0; j < i; j++) {
stars += " ";
}
for (let k = 0; k < (num - i) * 2 - 1; k++) {
stars += "*";
}
console.log(stars);
} else {
for (let j=0; j<2*(num-1)-i; j++) {
stars += " ";
}
for(let j=0; j<(i+1-num)*2+1; j++) {
stars += "*";
}
console.log(stars);
}
}
}
코드에서 어려운 부분은 없었으나 오래걸렸다 난 하수다
LIST
'코테 > 코테withJS' 카테고리의 다른 글
| 백준 Node.js(자바스크립트) 10808번 알파벳 개수(아스키코드) (0) | 2021.09.22 |
|---|---|
| 백준 Node.js(자바스크립트) 1267번 핸드폰 요금 (0) | 2021.09.21 |
| 백준 Node.js(자바스크립트) 1011문제 Fly me to the Alpha Centauri (0) | 2021.09.10 |
| 백준 Node.js(자바스크립트) 2839번 설탕배달 (0) | 2021.09.10 |
| 백준 Node.js(자바스크립트) 2869번 달팽이올라가는 문제 (0) | 2021.08.29 |