Instantly share code, notes, and snippets.

@Kaldrax /.js
Last active Jul 12, 2018

Embed
What would you like to do?
Node.js Riot Games API get matches & win by matchlist
summonerData.matches = [];
matchlist.matches.map(function (match) {
return qRequest(server, "/match/v3/matches/" + match.gameId).then(function(json){
summonerData.gamesLoaded++;
const match = JSON.parse(json);
summonerData.matches.push({
id: match.gameId,
time: match.gameCreation,
hour: (new Date(match.gameCreation)).getHours(),
win: check4win(match, summonerData.accountId)
});
return match;
});
});
function check4win(matchdata, accountId) {
const winnerTeam = matchdata.teams.find((a) => a.win === "Win");
const participant = matchdata.participantIdentities.find((a) => a.player.currentAccountId === accountId);
return winnerTeam.teamId === 100 && participant.participantId < 5 || winnerTeam.teamId === 200 && participant.participantId > 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment