title: Scaling backend calculations to support n array of <tr> records, each with 3 values to sum
body: <p>We have a site with automatically API generated  football team records where users can enter a value for wins, losses, and draws which are then later tabulated for each team (i.e. Patriots wins: 2, losses: 1, draws: 1 or (2+1+1=4).</p>
  
  <pre><code>  &lt;tr&gt;&lt;th scope="row"&gt;1&lt;/th&gt;
        &lt;td&gt;Patriots&lt;/td&gt;
        &lt;td&gt;7-2-0&lt;/td&gt;
        &lt;td&gt;&lt;input name="win[]" class="form-control col-xs-2 win" id="wins-1" value="0"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="loss[]" class="form-control col-xs-2 loss" id="loss-1" value="0"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="draw[]" class="form-control col-xs-2 draw" id="draw-1" value="0"&gt;&lt;/td&gt;
        &lt;td id="odds-1"&gt;4&lt;/td&gt; 
        &lt;td id="earn-1"&gt;0&lt;/td&gt;
        &lt;/tr&gt;
  </code></pre>
  
  <p>We wanted to move away from a fixed 3 team model, and be able to support n number of teams where each on can have their wins losses and draws added. Moreover results (teamearnings)are returned to their respective API generated record.</p>
  
  <pre><code> wins1 = $("#wins-1").val().trim(); &lt;-- fixed at 3 records only
   loss1 = $("#loss-1").val().trim();
   draw1 = $("#draw-1").val().trim();
  
   wins2 = $("#wins-2").val().trim();
   loss2 = $("#loss-2").val().trim();
   draw2 = $("#draw-2").val().trim();
  
   wins3 = $("#wins-3").val().trim();
   loss3 = $("#loss-3").val().trim();
   draw3 = $("#draw-3").val().trim();
  
   team1earn = parseInt(wins1) + parseInt(loss1) + parseInt(draw1);
   team2earn = parseInt(wins2) + parseInt(loss2) + parseInt(draw2);
   team3earn = parseInt(wins3) + parseInt(loss3) + parseInt(draw3);
  
   totalbets = team1earn + team2earn + team3earn
  
   tokensearned = totaltokens - totalbets
  
   $("#earn-1").text(team1earn); &lt;- returns calculations for 3 records only
   $("#earn-2").text(team2earn);
   $("#earn-3").text(team3earn);
  
   $("#totalearnings").text(totalbets);
   $("#tokens-earned").text(tokensearned); 
  </code></pre>
  
  <p>We are using the each function to find every instance of win, loss, and draw to simplify and hopefully scale capabilities, but we are not sure this approach is right nor is it giving us the expected calculations.</p>
  
  <pre><code>$("tr").each(function() {
  if ($(this).find(".win")) {
  team1earn = parseInt($(this).find(".win").val().trim())
  team2earn = parseInt($(this).find(".loss").val().trim())
  team3earn = parseInt($(this).find(".draw").val().trim())
  }
  })
  </code></pre>
  
  <p>Maybe we should be using a loop within loop where we as we read each football team record, we then add wins, losses, and draws and pass that to yet another another array that contains totals for n teams. Take those n team totals to come up with a grand total. If that makes sense.</p>