👽
frontend-survival
  • Dev Note
    • 🐣1주차
      • 개발환경
      • TypeScript
      • React
      • Testing Library
      • Parcel & ESlint
    • 🐥2주차
      • JSX
      • Virtual DOM
    • 🐥3주차
      • React Component
      • React State
    • 🐥4주차
      • Express
      • fetch API & CORS
      • React Hooks
      • useRef & custom hook
      • usehooks-ts
    • 🐥5주차
      • TDD
      • React Testing Library
      • MSW
    • 🐥6주차
      • external store
      • tsyringe
    • 🐥7주차
      • routing
      • routes
      • router
      • navigation
    • 🐥8주차
      • design system
      • style basics
      • styled components
    • 🐥javascript
      • promise
    • 🐥practice
      • 240102
      • 240103
      • 240423
      • 240424
      • 240426
      • 240430
      • 240501
      • 240506
      • 240508
      • 240512
      • 240514
      • 240515
      • 240714
      • 240716
      • 240717
      • 240808
      • 240813
      • 240816
      • 240819
      • 240820
      • 240826
      • 240904
      • 240906
      • 240909
      • 241021
    • 🐥react
      • state
      • global state
      • Context
      • module state
    • 🐥Next.js
      • app router
    • 🐥algorithm
      • reverse string
      • palindrome
      • reverse int
      • max char
      • chunk
      • anagrams
      • capitalize
      • printing step
      • pyramids
      • vowels
      • matrix spiral
      • queue from stack
    • 🐥css
      • mobile inner height
    • 🐥Clean Architecture
      • object oriented programming
Powered by GitBook
On this page
  • problem
  • solution
  1. Dev Note
  2. 🐥algorithm

pyramids

problem

n이 주어졌을 때, n의 길이만큼 피라미드를 출력하기 ex ) n = 3

  #
 ###
#####

solution

function printPyramid(n) {
    const midpoint = Math.floor((2 * n - 1) / 2)

    for(let row = 0; row < n; row++) {
        let level = ''

        for(let column = 0; column < 2 * n -1; colum++) {
            if(midpoint - row <= column && midpoint + row >= column) {
                level += '#'
            } else {
                level += ' '
            }
        }
    }
}
Previousprinting stepNextvowels

Last updated 1 year ago