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.
javascript jquery
add a comment |
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.
javascript jquery
Using loops is the most efficient way to scale repetitive code on repeating elements
– charlietfl
Nov 10 at 20:01
add a comment |
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.
javascript jquery
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
javascript jquery
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Using loops is the most efficient way to scale repetitive code on repeating elements
– charlietfl
Nov 10 at 20:01