Skip to content

Commit 7066155

Browse files
Reindent
1 parent 5474773 commit 7066155

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

src/CircleOfSuck.ts

+40-40
Original file line numberDiff line numberDiff line change
@@ -43,51 +43,51 @@ type CircleOfSuckEdge = {
4343
}
4444

4545
const findCircleOfSuck = async (teams: Team[], games: Game[]): Promise<CircleOfSuckEdge[] | null> => {
46-
// maps winner team -> loser team
47-
const gameGraph = _.fromPairs(_.map(teams, ({ school }) => [school, [] as string[]]))
48-
49-
// contains all future games, as [home_team, away_team] pairs
50-
const futureGames = [] as [string, string][]
51-
52-
_.each(games, ({ conference_game, away_team, home_team, away_points, home_points }) => {
53-
if (!conference_game) {
54-
return
55-
}
56-
57-
if (away_points === null || home_points === null) {
58-
futureGames.push([home_team, away_team])
59-
} else if (away_points > home_points) {
60-
gameGraph[away_team].push(home_team)
61-
} else {
62-
gameGraph[home_team].push(away_team)
63-
}
64-
})
46+
// maps winner team -> loser team
47+
const gameGraph = _.fromPairs(_.map(teams, ({ school }) => [school, [] as string[]]))
6548

66-
const teamToIndex = _.fromPairs(_.map(teams, ({ school }, i) => [school, i]))
49+
// contains all future games, as [home_team, away_team] pairs
50+
const futureGames = [] as [string, string][]
6751

68-
const graph = new WeightedDiGraph(teams.length)
69-
_.each(gameGraph, (losers, winner) => {
70-
_.each(losers, (loser) => {
71-
graph.addEdge(teamToIndex[winner], teamToIndex[loser], 0)
72-
})
73-
})
74-
_.each(futureGames, ([home, away]) => {
75-
graph.addEdge(teamToIndex[home], teamToIndex[away], 1)
76-
graph.addEdge(teamToIndex[away], teamToIndex[home], 1)
77-
})
52+
_.each(games, ({ conference_game, away_team, home_team, away_points, home_points }) => {
53+
if (!conference_game) {
54+
return
55+
}
7856

79-
const hamiltonian = getHamiltonian(graph)
80-
if (!hamiltonian) {
81-
return null
57+
if (away_points === null || home_points === null) {
58+
futureGames.push([home_team, away_team])
59+
} else if (away_points > home_points) {
60+
gameGraph[away_team].push(home_team)
61+
} else {
62+
gameGraph[home_team].push(away_team)
8263
}
64+
})
8365

84-
return _.map(hamiltonian.map((v) => teams[v]), (team1, i, arr) => {
85-
const team2 = arr[i === arr.length - 1 ? 0 : i + 1]
66+
const teamToIndex = _.fromPairs(_.map(teams, ({ school }, i) => [school, i]))
8667

87-
return {
88-
from: team1,
89-
to: team2,
90-
isPlayed: _.includes(gameGraph[team1.school], team2.school),
91-
}
68+
const graph = new WeightedDiGraph(teams.length)
69+
_.each(gameGraph, (losers, winner) => {
70+
_.each(losers, (loser) => {
71+
graph.addEdge(teamToIndex[winner], teamToIndex[loser], 0)
9272
})
73+
})
74+
_.each(futureGames, ([home, away]) => {
75+
graph.addEdge(teamToIndex[home], teamToIndex[away], 1)
76+
graph.addEdge(teamToIndex[away], teamToIndex[home], 1)
77+
})
78+
79+
const hamiltonian = getHamiltonian(graph)
80+
if (!hamiltonian) {
81+
return null
9382
}
83+
84+
return _.map(hamiltonian.map((v) => teams[v]), (team1, i, arr) => {
85+
const team2 = arr[i === arr.length - 1 ? 0 : i + 1]
86+
87+
return {
88+
from: team1,
89+
to: team2,
90+
isPlayed: _.includes(gameGraph[team1.school], team2.school),
91+
}
92+
})
93+
}

0 commit comments

Comments
 (0)