function buildEntries(nation: Nation, week: WRankWeek): LeaderboardEntry[] { const wRankEntries = WRank.entriesForNation(nation, week); return wRankEntries.map((wr): LeaderboardEntry => { const char = wr.character; // Aggregate K/D and stats from all active slots this week let totalKills = 0; let totalDeaths = 0; let totalAtk = 0; let totalDef = 0; let totalHeal = 0; for (const historyKey of (WRank.currentWeek().scoreIndex[char.name] ?? [])) { const score = Score.get({ character: char, slot: TGKey.parse(historyKey as TGKey).slot, historyKey: historyKey as TGKey, }); if (!score) continue; totalKills += score.k ?? 0; totalDeaths += score.d ?? 0; totalAtk += score.atk ?? 0; totalDef += score.def ?? 0; totalHeal += score.heal ?? 0; } return { character: char, weeklyPts: wr.weeklyPoints, tgCount: wr.tgCount, totalKills, totalDeaths, stats: { atk: totalAtk || undefined, def: totalDef || undefined, heal: totalHeal || undefined, }, currentRank: wr.currentRank, previousRank: wr.previousRank, leavesCount: Leaves.countForChar({ characterName: char.name }), }; }); }