Printing steps in Js
Oct 19, 2020
This is a common question which usually interviewers like to ask. So what is the question printing steps means? Basically, the function should console log a step shape with N levels using the # character. Also, make sure the step has spaces on the right hand side. Example, if we call step(2), it should give us two steps and it's supposed to form a visual staircase.
Solution 1:
- We will create a for loop to iterate through the rows from 0 — n
2. For each we will consider we will
- Create and empty string, ‘stair’
3. We will iterate through the columns 0–n
- If the current column is equal to or less than the current row
- Add a ‘#’ to ‘stair’
- Else add a space to ‘stair’
2. Console log ‘stair’
See the link below if you need to learn about for loop in Javascript