Skip to main content

This traditional JSJavascript code works fine:

function staircase(n) {
  var line = Array(n + 1).fill(' ');
  //line[n] = '';
  for (var i = n - 1; i >= 0; i--) {
    line[i] = '#';
    console.log(line.join(''));
  }
}

and ES6 we can write:

const staircase = n => {
  const line = Array(n + 1).fill(' ');
  //line[n] = ''; 
  for (let i = n - 1; i >= 0; i--) {
    line[i] = '#';
    console.log(line.join(''));
  }
}

If our given input is 6 the output should be:

     #
    ##
   ###
  ####
 #####
######

This traditional JS code works fine:

function staircase(n) {
  var line = Array(n + 1).fill(' ');
  line[n] = '';
  for (var i = n - 1; i >= 0; i--) {
    line[i] = '#';
    console.log(line.join(''));
  }
}

and ES6 we can write:

const staircase = n => {
  const line = Array(n + 1).fill(' ');
  line[n] = '';
  for (let i = n - 1; i >= 0; i--) {
    line[i] = '#';
    console.log(line.join(''));
  }
}

If our given input is 6 the output should be:

     #
    ##
   ###
  ####
 #####
######

This traditional Javascript code works fine:

function staircase(n) {
  var line = Array(n + 1).fill(' ');
  //line[n] = '';
  for (var i = n - 1; i >= 0; i--) {
    line[i] = '#';
    console.log(line.join(''));
  }
}

and ES6 we can write:

const staircase = n => {
  const line = Array(n + 1).fill(' ');
  //line[n] = ''; 
  for (let i = n - 1; i >= 0; i--) {
    line[i] = '#';
    console.log(line.join(''));
  }
}

If our given input is 6 the output should be:

     #
    ##
   ###
  ####
 #####
######
Source Link

This traditional JS code works fine:

function staircase(n) {
  var line = Array(n + 1).fill(' ');
  line[n] = '';
  for (var i = n - 1; i >= 0; i--) {
    line[i] = '#';
    console.log(line.join(''));
  }
}

and ES6 we can write:

const staircase = n => {
  const line = Array(n + 1).fill(' ');
  line[n] = '';
  for (let i = n - 1; i >= 0; i--) {
    line[i] = '#';
    console.log(line.join(''));
  }
}

If our given input is 6 the output should be:

     #
    ##
   ###
  ####
 #####
######