Skip to main content
1 of 3
CodeYogi
  • 5.1k
  • 12
  • 50
  • 104

Printing staircase revisited

What can be more elegant ways to solve the given problem.

    #
   ##
  ###
 ####

Code:

function StairCase(n) {
    for (var i = 1; i <= n; i++) {
        var row = i;
        for(var j = 1; j <= n - row; j++) {
            process.stdout.write(' ');
        }
        for(var j = 1; j <= row; j++) {
            process.stdout.write('#');
        }
        process.stdout.write('\n');
    }

}
CodeYogi
  • 5.1k
  • 12
  • 50
  • 104