javascript - create an object containing objects based on JSON data
You could dry up this code by adding some helper functions.

For example instead of this:


$scope.gamesSchedule.forEach(function(gameData) {
  var homeTeam = gameData.team1;
  var awayTeam = gameData.team2;
    if (homeTeam) {
        if (!$scope.homeVsAwaySchedules[homeTeam]) {
            $scope.homeVsAwaySchedules[homeTeam] = {
                "Home Games": 0,
                "Away Games": 0
            };
        }
    }
    if (awayTeam) {
        if (!$scope.homeVsAwaySchedules[awayTeam]) {
            $scope.homeVsAwaySchedules[awayTeam] = {
                "Home Games": 0,
                "Away Games": 0
            };
        }
    }
})



You could write using a helper function:

$scope.gamesSchedule.forEach(function(gameData) {
    function checkTeam(team) {
        if (team) {
            if (!$scope.homeVsAwaySchedules[team]) {
                $scope.homeVsAwaySchedules[team] = {
                    "Home Games": 0,
                    "Away Games": 0
                };
            }
        }
    }
    checkTeam(gameData.team1);
    checkTeam(gameData.team2);
})


Similarly, instead of this:


$scope.gamesSchedule.forEach(function(gameData) {
  var homeTeam = gameData.team1;
  var awayTeam = gameData.team2;
    if (homeTeam) {
        if ($scope.homeVsAwaySchedules[homeTeam]) {
            $scope.homeVsAwaySchedules[homeTeam]["Home Games"]++;
        }
    }
    if (awayTeam) {
        if ($scope.homeVsAwaySchedules[awayTeam]) {
            $scope.homeVsAwaySchedules[awayTeam]["Away Games"]++;
        }
    }
})



You could write using a helper function:

$scope.gamesSchedule.forEach(function(gameData) {
    function updateTeamSchedule(team, games) {
        if (team) {
            if ($scope.homeVsAwaySchedules[team]) {
                $scope.homeVsAwaySchedules[team][games]++;
            }
        }
    }
    updateTeamSchedule(gameData.team1);
    updateTeamSchedule(gameData.team2);
})