title: Javascript - Creating pyramid array from number values
body: <p>I am looking to create a pyramid array from number values. The requirement is that I am to work from an array that which in my case has 3 rows with 5 columns. I need to create a pyramid that looks like the example below.</p>
  
  <p>Here is what I want to achieve exactly..</p>
  
  <pre><code>[0, 0, 1, 0, 0]
  [0, 1, 1, 1, 0]
  [1, 1, 1, 1, 1]
  </code></pre>
  
  <p>So far my code looks something like this..</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var a = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]];
  
  function array_pyramid( array ){
      for (i = 0; i &lt; array.length; i++){
          for (j = 0; j &lt;= Math.floor(array[i].length / 2); j++){
              var tmp = array[i].length / 2;
              console.log (Math.floor(tmp));
              if ( i &lt; j ) {
                  array[i][j] = 1;
              }
          }
      }
      return array;
  }
  
  function print_array(array) {
      for (var i = 0; i &lt; array.length; i++) {
          console.log(array[i]);
      }
  }
  
  //console.log(a);
  //print_array(a);
  print_array(array_pyramid(a));</code></pre>
  </div>
  </div>
  </p>