Staircase

Staircase

Consider a staircase of size n = 4:

1
2
3
4
   #
##
###
####

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.


Function Description

Complete the staircase function in the editor below. It should print a staircase as described above.

staircase has the following parameter(s):

  • n: an integer

Input Format

A single integer, n, denoting the size of the staircase.


Constraints


Output Format

Print a staircase of size using # symbols and spaces.

Note: The last line must have spaces in it.


Sample Input

1
6

Sample Output

1
2
3
4
5
6
     #
##
###
####
#####
######

Explanation

The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of n = 6.



Solution

1
2
3
4
5
6
7
8
9
function staircase(n) {
let strings = Array(n).fill('#');

return strings.reduceRight((target, string, index) => {
target.push([...strings].join('').replace('#'.repeat(index), ' '.repeat(index)));

return target
}, []).join('\n');
}

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×