DEV Community

Discussion on: Printing Staircase in JavaScript

Collapse
 
harrywonder profile image
stephen

Real smooth. But you could cut down on the second loop and achieve it this way too.

function StairCase(stairCaseLength) {
  let stairs = "";
  for (let i = 0; i < stairCaseLength; i++) {
    let stair = "#".repeat(i + 1) + "\n";
    stairs += stair;
  }

  console.log(stairs.trim());
}

StairCase(6);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mohammadkhalid23 profile image
Mohammad Khalid

but time complexity would be same because of .repeat