title: Nested for loop and alternate map method
body: <p>I'm a beginner in javascript, so bear with me if this question is too simple. I'm trying to simplify this function</p>
  
  <pre><code>var calculateTotal =function(nodeData){
  
      var totalSelectedUnit0 = 0;
      var totalSelectedUnit1 = 0;
      var totalSelectedUnit2 = 0;
  
      for(x=$scope.selectFrom; x&lt;$scope.selectTo; x++){
          totalSelectedUnit0 += nodeData.items[0].usage.categories[x].current;
          totalSelectedUnit1 += nodeData.items[1].usage.categories[x].current;
          totalSelectedUnit2 += nodeData.items[2].usage.categories[x].current;
      }
      console.log(totalSelectedUnit0);
      console.log(totalSelectedUnit1);
      console.log(totalSelectedUnit2);
  
  };
  
  calculateTotal(node);
  </code></pre>
  
  <p>And this is how I attempted to refactor the code</p>
  
  <pre><code>var calculateTotal =function(nodeData){
      var totalSelectedUnit=[];
      for(i=0; i&lt;nodeData.items.length; i++){
          for(x=$scope.selectFrom; x&lt;$scope.selectTo; x++){
              totalSelectedUnit[i] += nodeData.items[i].usage.categories[x].current;
          }
      }
      console.log(totalSelectedUnit);
  };
  </code></pre>
  
  <p>There are couple of things I'm trying to achieve here. The calculation should ignore <code>null</code> or <code>Nan</code> values. Also I would like to use the <code>map</code> and <code>reduce</code> to achieve this calculation.</p>