From 6d22e3a2bbc0db1feca587dc237f4253601da0b1 Mon Sep 17 00:00:00 2001 From: contre95 Date: Wed, 15 Feb 2023 22:23:51 +0100 Subject: [PATCH] [INFRASEC-3212] Solving merge conflict --- exercises/hashmaps/hashmaps2.rs | 1 - exercises/hashmaps/hashmaps3.rs | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/exercises/hashmaps/hashmaps2.rs b/exercises/hashmaps/hashmaps2.rs index 429bc44f..7019f9c8 100644 --- a/exercises/hashmaps/hashmaps2.rs +++ b/exercises/hashmaps/hashmaps2.rs @@ -11,7 +11,6 @@ // // Execute `rustlings hint hashmaps2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE use std::collections::HashMap; diff --git a/exercises/hashmaps/hashmaps3.rs b/exercises/hashmaps/hashmaps3.rs index ad3baa68..1733ff1c 100644 --- a/exercises/hashmaps/hashmaps3.rs +++ b/exercises/hashmaps/hashmaps3.rs @@ -40,6 +40,51 @@ 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. + + let t1: Team = Team { + name: team_1_name.clone(), + goals_scored: team_1_score, + goals_conceded: team_2_score, + }; + + let t2: Team = Team { + name: team_2_name.clone(), + goals_scored: team_2_score, + goals_conceded: team_1_score, + }; + + let t1 = scores + .entry(team_1_name) + .and_modify(|ot1| { + ot1.goals_scored += t1.goals_scored; + ot1.goals_conceded += t1.goals_conceded; + }) + .or_insert(t1); + + let t2 = scores + .entry(team_2_name) + .and_modify(|ot2| { + ot2.goals_scored += t2.goals_scored; + ot2.goals_conceded += t2.goals_conceded; + }) + .or_insert(t2); + + // match scores.get_mut(&team_1_name){ + // Some(ot1) => { + // ot1.goals_scored += t1.goals_scored; + // ot1.goals_conceded += t1.goals_conceded; + // }, + // None => {scores.insert(team_1_name, t1);}, + // } + // + // match scores.get_mut(&team_2_name){ + // Some(ot2) => { + // ot2.goals_scored += t2.goals_scored; + // ot2.goals_conceded += t2.goals_conceded; + // }, + // None => {scores.insert(team_2_name, t2);}, + // } + // } scores }