I have an array of objects (coming from a ajax/PDO call), like this:
signincounts: [{ status: 1
   count:  3
   teamid: 4
 },{
   status: 0
   count:  1
   teamid: 2
 },{
   status: 0
   count:  2
   teamid: 4
}]
These object represent the number of users signin in for a particular event:
- status = 1 (signed in, will attend)
- status = 0 (signed out, will not attend)
- count = x number of people signing in/out
- teamid = y the team they belong to
In addition, I have the following information:
teamcount : {
    2: 5
    4: 6
}
- teamid : total number of players
I now want to sort this in Javascript to display the signin stats like this:
team 2: signed in/ signed out / not yet decided
team 4: signed in/ signed out / not yet decided
In this case that would be:
team 2: 0 / 1 / 4
team 4: 3 / 2 / 1
The difficulties:
- teamids are unique, but not necessarily sequential
- if the count for a status is zero, it is not part of the returned JSON
- objects are not necessarily in order
- there can anywhere from two to dozens of teams
- The string output should be sorted by teamid, with the team of the viewer at the top (there's an additional variable, playerteamid, which can be used to simply check against)
I was thinking I need to sort it, but am unsure on how to approach this because of undefined zero counts and non-sequential teamids. My initial plan was to use two empty arrays (signin_count, signout_count), then loop over the ajax JSON and push the counts in there (and unshift in case it's the player team). However, how can I keep the teamid reference and undefined values in there (so indices remain "parallel")? And I'm assuming there's a cleaner & better way anyway (on the array-of-objects level itself), that'd allow me to sort it straight into the result string.
Tried searching as well, but didn't find anything for the double-sort-while-considering-specific-key/value-pairs problem.
Would be glad for some pointers.
 
     
     
     
    