JS pyramid *

by Himanshu Joshi

JavaScript

function StairCase(n) {
  var ctr = 0,
    i = 0,
    j = 0;
  var arr = [];
  for (j = 0; j < n; j++) {
    arr[j] = [];
    ctr = 0;
    for (i = 0; i < n; i++) {
      if (ctr < (n - j - 1)) {
        arr[j].push(" ");
      } else {
        arr[j].push("*");
      }
      ctr++;
    }
  }
  for (j = 0; j < n; j++) {
    for (i = 0; i < n; i++) {
      console.log(arr[j][i]);// inspect the array here.
    }
  }
}

StairCase(5);