diff --git a/exercises/10_modules/modules1.rs b/exercises/10_modules/modules1.rs index d97ab23a..81981dfc 100644 --- a/exercises/10_modules/modules1.rs +++ b/exercises/10_modules/modules1.rs @@ -5,7 +5,7 @@ mod sausage_factory { String::from("Ginger") } - fn make_sausage() { + pub fn make_sausage() { get_secret_recipe(); println!("sausage!"); } diff --git a/exercises/10_modules/modules2.rs b/exercises/10_modules/modules2.rs index 02eb80a9..56e1402a 100644 --- a/exercises/10_modules/modules2.rs +++ b/exercises/10_modules/modules2.rs @@ -4,8 +4,8 @@ #[allow(dead_code)] mod delicious_snacks { // TODO: Add the following two `use` statements after fixing them. - // use self::fruits::PEAR as ???; - // use self::veggies::CUCUMBER as ???; + pub use self::fruits::PEAR as fruit; + pub use self::veggies::CUCUMBER as veggie; mod fruits { pub const PEAR: &str = "Pear"; diff --git a/exercises/10_modules/modules3.rs b/exercises/10_modules/modules3.rs index 691608d2..403b7ea1 100644 --- a/exercises/10_modules/modules3.rs +++ b/exercises/10_modules/modules3.rs @@ -3,7 +3,7 @@ // TODO: Bring `SystemTime` and `UNIX_EPOCH` from the `std::time` module into // your scope. Bonus style points if you can do it with one line! -// use ???; +use std::time::{SystemTime, UNIX_EPOCH}; fn main() { match SystemTime::now().duration_since(UNIX_EPOCH) { diff --git a/exercises/11_hashmaps/hashmaps1.rs b/exercises/11_hashmaps/hashmaps1.rs index 74001d04..0b8759e6 100644 --- a/exercises/11_hashmaps/hashmaps1.rs +++ b/exercises/11_hashmaps/hashmaps1.rs @@ -8,12 +8,14 @@ use std::collections::HashMap; fn fruit_basket() -> HashMap { // TODO: Declare the hash map. - // let mut basket = + let mut basket = HashMap::new(); // Two bananas are already given for you :) basket.insert(String::from("banana"), 2); // TODO: Put more fruits in your basket. + basket.insert(String::from("apple"), 3); + basket.insert(String::from("watermelon"), 1); basket } diff --git a/exercises/11_hashmaps/hashmaps2.rs b/exercises/11_hashmaps/hashmaps2.rs index 376970d7..27dcaf68 100644 --- a/exercises/11_hashmaps/hashmaps2.rs +++ b/exercises/11_hashmaps/hashmaps2.rs @@ -29,9 +29,7 @@ fn fruit_basket(basket: &mut HashMap) { ]; for fruit in fruit_kinds { - // TODO: Insert new fruits if they are not already present in the - // basket. Note that you are not allowed to put any type of fruit that's - // already present! + basket.entry(fruit).or_insert(1); } } diff --git a/exercises/11_hashmaps/hashmaps3.rs b/exercises/11_hashmaps/hashmaps3.rs index 9f8fdd78..262e78bf 100644 --- a/exercises/11_hashmaps/hashmaps3.rs +++ b/exercises/11_hashmaps/hashmaps3.rs @@ -27,10 +27,12 @@ fn build_scores_table(results: &str) -> HashMap<&str, Team> { let team_1_score: u8 = split_iterator.next().unwrap().parse().unwrap(); let team_2_score: u8 = split_iterator.next().unwrap().parse().unwrap(); - // 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 - // number of goals conceded by team 1. + let entry1 = scores.entry(team_1_name).or_insert(Team { goals_scored: 0, goals_conceded: 0 }); + entry1.goals_scored += team_1_score; + entry1.goals_conceded += team_2_score; + let entry2 = scores.entry(team_2_name).or_insert(Team { goals_scored: 0, goals_conceded: 0 }); + entry2.goals_scored += team_2_score; + entry2.goals_conceded += team_1_score; } scores diff --git a/exercises/quizzes/quiz2.rs b/exercises/quizzes/quiz2.rs index 8ef1342a..ca1339e6 100644 --- a/exercises/quizzes/quiz2.rs +++ b/exercises/quizzes/quiz2.rs @@ -27,7 +27,21 @@ mod my_module { use super::Command; // TODO: Complete the function. - // pub fn transformer(input: ???) -> ??? { ??? } + pub fn transformer(input: Vec<(String, Command)>) -> Vec { + input.iter().map(|(item, cmd)| { + match cmd { + Command::Uppercase => { + item.to_uppercase() + } + Command::Trim => { + item.trim().to_string() + } + Command::Append(size) => { + format!("{}{}", item, "bar".repeat(*size)) + } + } + }).collect() + } } fn main() { @@ -37,7 +51,7 @@ fn main() { #[cfg(test)] mod tests { // TODO: What do we need to import to have `transformer` in scope? - // use ???; + use super::my_module::{transformer}; use super::Command; #[test]