title: 2D array diagonal checking loop
body: <p>I tried to create a 2D array and place four "X" in diagonal and created a double loop for detecting and counting the number of Xs ,it works but it doesnt do the job properly what it really does is that it counts the number of Xs in every row, my question how can i make it count just the Xs on diagonal ?</p>
  
  <pre><code>    var creatematrix = function (nbRang, nbColumn) {
          var result = Array(nbRang);
          for (var i=0; i&lt;nbRang; i++) {
              result[i] = Array(nbColumn);
          }
          return result;
      };
  
      var m = creatematrix(6, 7);
  </code></pre>
  
  <p>for example if i did this </p>
  
  <pre><code>      m[4][1] = "X";
        m[3][2] = "X";
        m[2][3] = "X";
        m[1][4] = "X";
  
        m[5][3] = "O";
        m[3][3] = "O";
        m[4][3] = "O";
        m[2][4] = "O";
  </code></pre>
  
  <p>or this the result is the same</p>
  
  <pre><code>    m[1][1] = "X";
      m[2][1] = "X";
      m[3][1] = "X";
      m[4][1] = "X";
  
  
  
      m[5][3] = "O";
      m[3][3] = "O";
      m[4][3] = "O";
      m[2][4] = "O";
  </code></pre>
  
  <p>Here is what I have:</p>
  
  <pre><code>   var sumX = 0;
     for(var k = 5; k &gt;= 0  ; k--){
         if(sumX == 4){
             alert("player 1 won");
         }
         for(var i = 0 ; i&lt;= 6; i++){
             if(m[k][i]== "X" ){
                 sumX += 1;
                 break;
             }
             if(m[k][i]== "O" ){
                sumX = 0;         
             }
         }
     }    
  </code></pre>