text: const data = {
    "year": 2017,
    "regions": [
      [
        [
          [
            {
              "seed": 1,
              "team": "Villanova",
              "score": 76,
              "round_of": 64
            },
            {
              "seed": 16,
              "team": "Mount St. Mary's",
              "score": 56,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 8,
              "team": "Wisconsin",
              "score": 84,
              "round_of": 64
            },
            {
              "seed": 9,
              "team": "Virginia Tech",
              "score": 74,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 5,
              "team": "Virginia",
              "score": 76,
              "round_of": 64
            },
            {
              "seed": 12,
              "team": "UNC Wilmington",
              "score": 71,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 4,
              "team": "Florida",
              "score": 80,
              "round_of": 64
            },
            {
              "seed": 13,
              "team": "East Tennessee State",
              "score": 65,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 6,
              "team": "SMU",
              "score": 65,
              "round_of": 64
            },
            {
              "seed": 11,
              "team": "USC",
              "score": 66,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 3,
              "team": "Baylor",
              "score": 91,
              "round_of": 64
            },
            {
              "seed": 14,
              "team": "New Mexico State",
              "score": 73,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 7,
              "team": "South Carolina",
              "score": 93,
              "round_of": 64
            },
            {
              "seed": 10,
              "team": "Marquette",
              "score": 73,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 2,
              "team": "Duke",
              "score": 87,
              "round_of": 64
            },
            {
              "seed": 15,
              "team": "Troy",
              "score": 65,
              "round_of": 64
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "Villanova",
              "score": 62,
              "round_of": 32
            },
            {
              "seed": 8,
              "team": "Wisconsin",
              "score": 65,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 5,
              "team": "Virginia",
              "score": 39,
              "round_of": 32
            },
            {
              "seed": 4,
              "team": "Florida",
              "score": 65,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 11,
              "team": "USC",
              "score": 78,
              "round_of": 32
            },
            {
              "seed": 3,
              "team": "Baylor",
              "score": 82,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 7,
              "team": "South Carolina",
              "score": 88,
              "round_of": 32
            },
            {
              "seed": 2,
              "team": "Duke",
              "score": 81,
              "round_of": 32
            }
          ]
        ],
        [
          [
            {
              "seed": 8,
              "team": "Wisconsin",
              "score": 83,
              "round_of": 16
            },
            {
              "seed": 4,
              "team": "Florida",
              "score": 84,
              "round_of": 16
            }
          ],
          [
            {
              "seed": 3,
              "team": "Baylor",
              "score": 50,
              "round_of": 16
            },
            {
              "seed": 7,
              "team": "South Carolina",
              "score": 70,
              "round_of": 16
            }
          ]
        ],
        [
          [
            {
              "seed": 4,
              "team": "Florida",
              "score": 70,
              "round_of": 8
            },
            {
              "seed": 7,
              "team": "South Carolina",
              "score": 77,
              "round_of": 8
            }
          ]
        ]
      ],
      [
        [
          [
            {
              "seed": 1,
              "team": "Gonzaga",
              "score": 66,
              "round_of": 64
            },
            {
              "seed": 16,
              "team": "South Dakota State",
              "score": 46,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 8,
              "team": "Northwestern",
              "score": 68,
              "round_of": 64
            },
            {
              "seed": 9,
              "team": "Vanderbilt",
              "score": 66,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 5,
              "team": "Notre Dame",
              "score": 60,
              "round_of": 64
            },
            {
              "seed": 12,
              "team": "Princeton",
              "score": 58,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 4,
              "team": "West Virginia",
              "score": 86,
              "round_of": 64
            },
            {
              "seed": 13,
              "team": "Bucknell",
              "score": 80,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 6,
              "team": "Maryland",
              "score": 65,
              "round_of": 64
            },
            {
              "seed": 11,
              "team": "Xavier",
              "score": 76,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 3,
              "team": "Florida State",
              "score": 86,
              "round_of": 64
            },
            {
              "seed": 14,
              "team": "Florida Gulf Coast",
              "score": 80,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 7,
              "team": "Saint Mary's",
              "score": 85,
              "round_of": 64
            },
            {
              "seed": 10,
              "team": "VCU",
              "score": 77,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 2,
              "team": "Arizona",
              "score": 100,
              "round_of": 64
            },
            {
              "seed": 15,
              "team": "North Dakota",
              "score": 82,
              "round_of": 64
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "Gonzaga",
              "score": 79,
              "round_of": 32
            },
            {
              "seed": 8,
              "team": "Northwestern",
              "score": 73,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 5,
              "team": "Notre Dame",
              "score": 71,
              "round_of": 32
            },
            {
              "seed": 4,
              "team": "West Virginia",
              "score": 83,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 11,
              "team": "Xavier",
              "score": 91,
              "round_of": 32
            },
            {
              "seed": 3,
              "team": "Florida State",
              "score": 66,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 7,
              "team": "Saint Mary's",
              "score": 60,
              "round_of": 32
            },
            {
              "seed": 2,
              "team": "Arizona",
              "score": 69,
              "round_of": 32
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "Gonzaga",
              "score": 61,
              "round_of": 16
            },
            {
              "seed": 4,
              "team": "West Virginia",
              "score": 58,
              "round_of": 16
            }
          ],
          [
            {
              "seed": 11,
              "team": "Xavier",
              "score": 73,
              "round_of": 16
            },
            {
              "seed": 2,
              "team": "Arizona",
              "score": 71,
              "round_of": 16
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "Gonzaga",
              "score": 83,
              "round_of": 8
            },
            {
              "seed": 11,
              "team": "Xavier",
              "score": 59,
              "round_of": 8
            }
          ]
        ]
      ],
      [
        [
          [
            {
              "seed": 1,
              "team": "Kansas",
              "score": 100,
              "round_of": 64
            },
            {
              "seed": 16,
              "team": "UC Davis",
              "score": 62,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 8,
              "team": "Miami (FL)",
              "score": 58,
              "round_of": 64
            },
            {
              "seed": 9,
              "team": "Michigan State",
              "score": 78,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 5,
              "team": "Iowa State",
              "score": 84,
              "round_of": 64
            },
            {
              "seed": 12,
              "team": "Nevada",
              "score": 73,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 4,
              "team": "Purdue",
              "score": 80,
              "round_of": 64
            },
            {
              "seed": 13,
              "team": "Vermont",
              "score": 70,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 6,
              "team": "Creighton",
              "score": 72,
              "round_of": 64
            },
            {
              "seed": 11,
              "team": "Rhode Island",
              "score": 84,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 3,
              "team": "Oregon",
              "score": 93,
              "round_of": 64
            },
            {
              "seed": 14,
              "team": "Iona",
              "score": 77,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 7,
              "team": "Michigan",
              "score": 92,
              "round_of": 64
            },
            {
              "seed": 10,
              "team": "Oklahoma State",
              "score": 91,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 2,
              "team": "Louisville",
              "score": 78,
              "round_of": 64
            },
            {
              "seed": 15,
              "team": "Jacksonville State",
              "score": 63,
              "round_of": 64
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "Kansas",
              "score": 90,
              "round_of": 32
            },
            {
              "seed": 9,
              "team": "Michigan State",
              "score": 70,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 5,
              "team": "Iowa State",
              "score": 76,
              "round_of": 32
            },
            {
              "seed": 4,
              "team": "Purdue",
              "score": 80,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 11,
              "team": "Rhode Island",
              "score": 72,
              "round_of": 32
            },
            {
              "seed": 3,
              "team": "Oregon",
              "score": 75,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 7,
              "team": "Michigan",
              "score": 73,
              "round_of": 32
            },
            {
              "seed": 2,
              "team": "Louisville",
              "score": 69,
              "round_of": 32
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "Kansas",
              "score": 98,
              "round_of": 16
            },
            {
              "seed": 4,
              "team": "Purdue",
              "score": 66,
              "round_of": 16
            }
          ],
          [
            {
              "seed": 3,
              "team": "Oregon",
              "score": 69,
              "round_of": 16
            },
            {
              "seed": 7,
              "team": "Michigan",
              "score": 68,
              "round_of": 16
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "Kansas",
              "score": 60,
              "round_of": 8
            },
            {
              "seed": 3,
              "team": "Oregon",
              "score": 74,
              "round_of": 8
            }
          ]
        ]
      ],
      [
        [
          [
            {
              "seed": 1,
              "team": "North Carolina",
              "score": 103,
              "round_of": 64
            },
            {
              "seed": 16,
              "team": "Texas Southern",
              "score": 64,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 8,
              "team": "Arkansas",
              "score": 77,
              "round_of": 64
            },
            {
              "seed": 9,
              "team": "Seton Hall",
              "score": 71,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 5,
              "team": "Minnesota",
              "score": 72,
              "round_of": 64
            },
            {
              "seed": 12,
              "team": "Middle Tennessee",
              "score": 81,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 4,
              "team": "Butler",
              "score": 76,
              "round_of": 64
            },
            {
              "seed": 13,
              "team": "Winthrop",
              "score": 64,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 6,
              "team": "Cincinnati",
              "score": 75,
              "round_of": 64
            },
            {
              "seed": 11,
              "team": "Kansas State",
              "score": 61,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 3,
              "team": "UCLA",
              "score": 97,
              "round_of": 64
            },
            {
              "seed": 14,
              "team": "Kent State",
              "score": 80,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 7,
              "team": "Dayton",
              "score": 58,
              "round_of": 64
            },
            {
              "seed": 10,
              "team": "Wichita State",
              "score": 64,
              "round_of": 64
            }
          ],
          [
            {
              "seed": 2,
              "team": "Kentucky",
              "score": 79,
              "round_of": 64
            },
            {
              "seed": 15,
              "team": "Northern Kentucky",
              "score": 70,
              "round_of": 64
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "North Carolina",
              "score": 72,
              "round_of": 32
            },
            {
              "seed": 8,
              "team": "Arkansas",
              "score": 65,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 12,
              "team": "Middle Tennessee",
              "score": 65,
              "round_of": 32
            },
            {
              "seed": 4,
              "team": "Butler",
              "score": 74,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 6,
              "team": "Cincinnati",
              "score": 67,
              "round_of": 32
            },
            {
              "seed": 3,
              "team": "UCLA",
              "score": 79,
              "round_of": 32
            }
          ],
          [
            {
              "seed": 10,
              "team": "Wichita State",
              "score": 62,
              "round_of": 32
            },
            {
              "seed": 2,
              "team": "Kentucky",
              "score": 65,
              "round_of": 32
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "North Carolina",
              "score": 92,
              "round_of": 16
            },
            {
              "seed": 4,
              "team": "Butler",
              "score": 80,
              "round_of": 16
            }
          ],
          [
            {
              "seed": 3,
              "team": "UCLA",
              "score": 75,
              "round_of": 16
            },
            {
              "seed": 2,
              "team": "Kentucky",
              "score": 86,
              "round_of": 16
            }
          ]
        ],
        [
          [
            {
              "seed": 1,
              "team": "North Carolina",
              "score": 75,
              "round_of": 8
            },
            {
              "seed": 2,
              "team": "Kentucky",
              "score": 73,
              "round_of": 8
            }
          ]
        ]
      ]
    ],
    "finalfour": [
      [
        [
          {
            "seed": 7,
            "team": "South Carolina",
            "score": 73,
            "round_of": 4
          },
          {
            "seed": 1,
            "team": "Gonzaga",
            "score": 77,
            "round_of": 4
          }
        ],
        [
          {
            "seed": 3,
            "team": "Oregon",
            "score": 76,
            "round_of": 4
          },
          {
            "seed": 1,
            "team": "North Carolina",
            "score": 77,
            "round_of": 4
          }
        ]
      ],
      [
        [
          {
            "seed": 1,
            "team": "Gonzaga",
            "score": 65,
            "round_of": 2
          },
          {
            "seed": 1,
            "team": "North Carolina",
            "score": 71,
            "round_of": 2
          }
        ]
      ]
    ]
  }
  
  const teams = [];
  let teamId = 0;
  for (const region of data.regions) {
    const round = region[0];
    for (const roundGame of round) {
      const topTeam = roundGame[0];
      teams.push({
        teamId,
        teamName: topTeam.team,
        seed: topTeam.seed
      });
  
      teamId++;
  
      const bottomTeam = roundGame[1];
      teams.push({
        teamId,
        teamName: bottomTeam.team,
        seed: bottomTeam.seed
      });
      
      teamId++;
    }
  }
  
  console.log(JSON.stringify(teams, undefined, 2));
  
  const resultsByGameId = {};
  let gameId = 0;
  
  for (let round = 0; round < 4; round++) {
    for (let regionId = 0; regionId < 4; regionId++) {
      for (const game of data.regions[regionId][round]) {
        const topTeam = teams.find(t => t.teamName ===  game[0].team);
        const bottomTeam = teams.find(t => t.teamName ===  game[1].team);
        const winningTeamId = game[0].score > game[1].score ? topTeam.teamId : bottomTeam.teamId;
        resultsByGameId[gameId] = {
          topTeamId: topTeam.teamId,
          topTeamScore: game[0].score,
          bottomTeamId: bottomTeam.teamId,
          bottomTeamScore: game[1].score,
          winningTeamId,
          gameId
        }
        gameId++;
      }
    }
  }
  
  const finalGames = [...data.finalfour[0], ...data.finalfour[1]];
  for (const game of finalGames) {
    const topTeam = teams.find(t => t.teamName ===  game[0].team);
    const bottomTeam = teams.find(t => t.teamName ===  game[1].team);
    const winningTeamId = game[0].score > game[1].score ? topTeam.teamId : bottomTeam.teamId;
    resultsByGameId[gameId] = {
      topTeamId: topTeam.teamId,
      topTeamScore: game[0].score,
      bottomTeamId: bottomTeam.teamId,
      bottomTeamScore: game[1].score,
      winningTeamId,
      gameId
    }
    gameId++;
  }
  
  console.log(JSON.stringify(resultsByGameId, undefined, 2));
  