From 8b15f8d5115ee03410201c7bbce2495ce5453b34 Mon Sep 17 00:00:00 2001 From: AramJonghu Date: Tue, 4 Aug 2026 19:03:18 +0200 Subject: [PATCH] feat(section): hashmap + section complete w/ quiz2 --- exercises/11_hashmaps/hashmaps3.rs | 5 +++++ exercises/quizzes/quiz2.rs | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/exercises/11_hashmaps/hashmaps3.rs b/exercises/11_hashmaps/hashmaps3.rs index 5b390ab..b02c423 100644 --- a/exercises/11_hashmaps/hashmaps3.rs +++ b/exercises/11_hashmaps/hashmaps3.rs @@ -27,6 +27,11 @@ fn build_scores_table(results: &str) -> HashMap<&str, TeamScores> { let team_1_score: u8 = split_iterator.next().unwrap().parse().unwrap(); let team_2_score: u8 = split_iterator.next().unwrap().parse().unwrap(); + scores.entry(team_1_name).or_default().goals_scored += team_1_score; + scores.entry(team_2_name).or_default().goals_scored += team_2_score; + + scores.entry(team_1_name).or_default().goals_conceded += team_2_score; + scores.entry(team_2_name).or_default().goals_conceded += team_1_score; // TODO: Populate the scores table with the extracted details. // Keep in mind that goals scored by team 1 will be the number of goals // conceded by team 2. Similarly, goals scored by team 2 will be the diff --git a/exercises/quizzes/quiz2.rs b/exercises/quizzes/quiz2.rs index 2cddba9..d629a57 100644 --- a/exercises/quizzes/quiz2.rs +++ b/exercises/quizzes/quiz2.rs @@ -28,6 +28,25 @@ mod my_module { // TODO: Complete the function as described above. // pub fn transformer(input: ???) -> ??? { ??? } + + pub fn transformer(input: Vec<(String, Command)>) -> Vec { + let mut output = Vec::new(); + for (s, cmd) in input { + let transformed = match cmd { + Command::Uppercase => s.to_uppercase(), + Command::Trim => s.trim().to_owned(), + Command::Append(n) => { + let mut out = s; + for _ in 0..n { + out.push_str("bar"); + } + out + } + }; + output.push(transformed) + } + output + } } fn main() { @@ -39,6 +58,7 @@ mod tests { // TODO: What do we need to import to have `transformer` in scope? // use ???; use super::Command; + use crate::my_module::transformer; #[test] fn it_works() {