esfsef.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function getMostplayedOpponents() {
  2. const matches = this.state.wins
  3. const already: { opponents: { player1: string, player2: string }, matches: MatchResult[] }[] = [];
  4. for (let index = 0; index < matches.length; index++) {
  5. const match = matches[index];
  6. let alreadyAdded = false
  7. for (let index = 0; index < already.length; index++) {
  8. const alreadyAddedMatch = already[index];
  9. if (
  10. (match.losers[0].name == alreadyAddedMatch.opponents.player1 || match.losers[0].name == alreadyAddedMatch.opponents.player2) &&
  11. (match.losers[1].name == alreadyAddedMatch.opponents.player1 || match.losers[1].name == alreadyAddedMatch.opponents.player2)
  12. ) {
  13. // another game to this pair
  14. alreadyAdded = true;
  15. alreadyAddedMatch.matches.push(match)
  16. break;
  17. }
  18. }
  19. if (!alreadyAdded) {
  20. const pair = {
  21. opponents:
  22. {
  23. player1: match.losers[0].name,
  24. player2: match.losers[1].name
  25. },
  26. matches: []
  27. };
  28. //and add another game to the pair
  29. pair.matches.push(match);
  30. //add another pair
  31. already.push(pair)
  32. }
  33. }
  34. }
  35. if
  36. (matchResult.winners.length == 1 && (result.alias.name == matchResult.winners[0].name || result.alias.name == matchResult.losers[0].name) ||
  37. (matchResult.winners.length == 2 && result.partner != undefined && (
  38. (result.alias.name == matchResult.winners[0].name && result.partner.name == matchResult.winners[1].name || result.alias.name == matchResult.winners[1].name && result.partner.name == matchResult.winners[0].name) ||
  39. (result.alias.name == matchResult.losers[0].name && result.partner.name == matchResult.losers[1].name || result.alias.name == matchResult.losers[1].name && result.partner.name == matchResult.losers[0].name)
  40. )
  41. )
  42. )