diff --git a/exercises/11_hashmaps/hashmaps3.rs b/exercises/11_hashmaps/hashmaps3.rs index 08e977c3..771eb8f9 100644 --- a/exercises/11_hashmaps/hashmaps3.rs +++ b/exercises/11_hashmaps/hashmaps3.rs @@ -14,8 +14,6 @@ // Execute `rustlings hint hashmaps3` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE - use std::collections::HashMap; // A structure to store the goal details of a team. @@ -39,6 +37,25 @@ fn build_scores_table(results: String) -> HashMap { // will be the number of goals conceded from team_2, and similarly // goals scored by team_2 will be the number of goals conceded by // team_1. + scores.entry(team_1_name.clone()).or_insert(Team { + goals_scored: 0, + goals_conceded: 0 + }); + + scores.entry(team_2_name.clone()).or_insert(Team { + goals_scored: 0, + goals_conceded: 0 + }); + + if let Some(team) = scores.get_mut(&team_1_name) { + team.goals_scored += team_1_score; + team.goals_conceded += team_2_score; + } + + if let Some(team) = scores.get_mut(&team_2_name) { + team.goals_scored += team_2_score; + team.goals_conceded += team_1_score; + } } scores }