백준-Node.js-2441, 별 찍기 - 4

송철진·2023년 2월 11일
0

백준-Node.js

목록 보기
16/69

풀이

const fs = require('fs')
const input = fs.readFileSync('/dev/stdin').toString().trim()

const solution = (input) => {
  let result = []
  for(let i = 0; i<input; i++){
    result[i] = " ".repeat(i) + '*'.repeat(input-i)
  }
  return result.join('\n')
}

console.log(solution(input))

i의 초기값이 0 일 때
i 회만큼 공백' '을 반복하고 (input - i)회만큼 '*'을 반복해서 출력한다

profile
검색하고 기록하며 학습하는 백엔드 개발자

0개의 댓글