1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- function getMostplayedOpponents() {
- const matches = this.state.wins
- const already: { opponents: { player1: string, player2: string }, matches: MatchResult[] }[] = [];
- for (let index = 0; index < matches.length; index++) {
- const match = matches[index];
- let alreadyAdded = false
- for (let index = 0; index < already.length; index++) {
- const alreadyAddedMatch = already[index];
- if (
- (match.losers[0].name == alreadyAddedMatch.opponents.player1 || match.losers[0].name == alreadyAddedMatch.opponents.player2) &&
- (match.losers[1].name == alreadyAddedMatch.opponents.player1 || match.losers[1].name == alreadyAddedMatch.opponents.player2)
- ) {
- // another game to this pair
- alreadyAdded = true;
- alreadyAddedMatch.matches.push(match)
- break;
- }
- }
- if (!alreadyAdded) {
-
- const pair = {
- opponents:
- {
- player1: match.losers[0].name,
- player2: match.losers[1].name
- },
- matches: []
- };
- //and add another game to the pair
- pair.matches.push(match);
- //add another pair
- already.push(pair)
- }
- }
- }
- if
- (matchResult.winners.length == 1 && (result.alias.name == matchResult.winners[0].name || result.alias.name == matchResult.losers[0].name) ||
- (matchResult.winners.length == 2 && result.partner != undefined && (
- (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) ||
- (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)
- )
- )
- )
|