"*"의 높이와 너비를 1이라고 했을 때, "*"을 이용해 직각 이등변 삼각형을 그리려고합니다. 정수 n 이 주어지면 높이와 너비가 n 인 직각 이등변 삼각형을 출력하도록 코드를 작성해보세요.
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 () {
for (let i=1; i<=Number(input[0]); i++){
console.log('*'.repeat(i))
}
});
반복문을 통해, 1부터 정해진 숫자만큼 반복해 해당하는 i만큼 *를 console에 찍는다. 이렇게 간단하게 문제를 해결할 수 있었다.
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 () {
solution(Number(input[0]));
});
function solution(n) {
for(let i = 1; i < n + 1; i++) {
console.log('*'.repeat(i));
}
}
내 풀이와 비슷하지만 함수를 따로 뺀 방식. 좀 더 보기 좋은 것 같다.
기업 화상면접이 있었다. 꽤 어려운 질문들이 많이 나왔고, 취업을 위해서는 정신 차리고 한달인턴 중에도 열심히 해야겠다는 생각이 들었다. 주어진 시간은 많지 않고 해야할 것은 많다.