티스토리 뷰

Algorithms

Staircase

seoca 2020. 8. 4. 20:00

 

Problem

Observe that its base and height are both equal to n, and the image is drawn using # symbols and spaces. The last line is not preceded by any spaces.

Write a program that prints a staircase of size n.

 

 

Solution

function staircase(n) {
for (let i = 1; i <= n; i++) {
        console.log("#".repeat(i).padStart(n));
    }
}

 

Result

        #
      ##
    ###
  ####
#####

 

Reference

https://www.hackerrank.com/challenges/staircase/problem

 

Staircase | HackerRank

Print a right-aligned staircase with n steps.

www.hackerrank.com

 

'Algorithms' 카테고리의 다른 글

Birthday Cake Candles  (0) 2020.08.16
Mini-Max Sum  (0) 2020.08.04
Plus Minus  (0) 2020.07.29
Diagonal Difference in JavaScript  (0) 2020.07.27
Calculate the Max minus Min Value in Array  (0) 2019.09.08