DEV Community

Discussion on: StairCase | HackerRank solution in javascript

Collapse
 
devsmitra profile image
Rahul Sharma • Edited

padStart also can be used to solve this, for adding padding on string.

developer.mozilla.org/en-US/docs/W...

function staircase(n) {
  for (let i = 0; i < n; i++) {
    const line = Array(i + 1)
      .fill("#")
      .join("")
      .padStart(n);
    console.log(line);
  }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
biomathcode profile image
Pratik sharma

Ohh! okay thanks