Scaling backend calculations to support n array of records, each with 3 values to sum









up vote
1
down vote

favorite












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).



 <tr><th scope="row">1</th>
<td>Patriots</td>
<td>7-2-0</td>
<td><input name="win" class="form-control col-xs-2 win" id="wins-1" value="0"></td>
<td><input name="loss" class="form-control col-xs-2 loss" id="loss-1" value="0"></td>
<td><input name="draw" class="form-control col-xs-2 draw" id="draw-1" value="0"></td>
<td id="odds-1">4</td>
<td id="earn-1">0</td>
</tr>


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.



 wins1 = $("#wins-1").val().trim(); <-- 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); <- returns calculations for 3 records only
$("#earn-2").text(team2earn);
$("#earn-3").text(team3earn);

$("#totalearnings").text(totalbets);
$("#tokens-earned").text(tokensearned);


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.



$("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())

)


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.










share|improve this question





















  • Using loops is the most efficient way to scale repetitive code on repeating elements
    – charlietfl
    Nov 10 at 20:01















up vote
1
down vote

favorite












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).



 <tr><th scope="row">1</th>
<td>Patriots</td>
<td>7-2-0</td>
<td><input name="win" class="form-control col-xs-2 win" id="wins-1" value="0"></td>
<td><input name="loss" class="form-control col-xs-2 loss" id="loss-1" value="0"></td>
<td><input name="draw" class="form-control col-xs-2 draw" id="draw-1" value="0"></td>
<td id="odds-1">4</td>
<td id="earn-1">0</td>
</tr>


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.



 wins1 = $("#wins-1").val().trim(); <-- 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); <- returns calculations for 3 records only
$("#earn-2").text(team2earn);
$("#earn-3").text(team3earn);

$("#totalearnings").text(totalbets);
$("#tokens-earned").text(tokensearned);


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.



$("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())

)


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.










share|improve this question





















  • Using loops is the most efficient way to scale repetitive code on repeating elements
    – charlietfl
    Nov 10 at 20:01













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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).



 <tr><th scope="row">1</th>
<td>Patriots</td>
<td>7-2-0</td>
<td><input name="win" class="form-control col-xs-2 win" id="wins-1" value="0"></td>
<td><input name="loss" class="form-control col-xs-2 loss" id="loss-1" value="0"></td>
<td><input name="draw" class="form-control col-xs-2 draw" id="draw-1" value="0"></td>
<td id="odds-1">4</td>
<td id="earn-1">0</td>
</tr>


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.



 wins1 = $("#wins-1").val().trim(); <-- 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); <- returns calculations for 3 records only
$("#earn-2").text(team2earn);
$("#earn-3").text(team3earn);

$("#totalearnings").text(totalbets);
$("#tokens-earned").text(tokensearned);


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.



$("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())

)


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.










share|improve this question













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).



 <tr><th scope="row">1</th>
<td>Patriots</td>
<td>7-2-0</td>
<td><input name="win" class="form-control col-xs-2 win" id="wins-1" value="0"></td>
<td><input name="loss" class="form-control col-xs-2 loss" id="loss-1" value="0"></td>
<td><input name="draw" class="form-control col-xs-2 draw" id="draw-1" value="0"></td>
<td id="odds-1">4</td>
<td id="earn-1">0</td>
</tr>


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.



 wins1 = $("#wins-1").val().trim(); <-- 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); <- returns calculations for 3 records only
$("#earn-2").text(team2earn);
$("#earn-3").text(team3earn);

$("#totalearnings").text(totalbets);
$("#tokens-earned").text(tokensearned);


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.



$("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())

)


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.







javascript jquery






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 19:57









NanoNet

336




336











  • Using loops is the most efficient way to scale repetitive code on repeating elements
    – charlietfl
    Nov 10 at 20:01

















  • Using loops is the most efficient way to scale repetitive code on repeating elements
    – charlietfl
    Nov 10 at 20:01
















Using loops is the most efficient way to scale repetitive code on repeating elements
– charlietfl
Nov 10 at 20:01





Using loops is the most efficient way to scale repetitive code on repeating elements
– charlietfl
Nov 10 at 20:01


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242869%2fscaling-backend-calculations-to-support-n-array-of-tr-records-each-with-3-val%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242869%2fscaling-backend-calculations-to-support-n-array-of-tr-records-each-with-3-val%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto