This commit is contained in:
enforcer007 2022-11-13 13:31:41 +05:30
parent b670cd849b
commit d475cef554
4 changed files with 24 additions and 11 deletions

View File

@ -10,18 +10,17 @@
//
// Execute `rustlings hint hashmaps1` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
use std::collections::HashMap;
fn fruit_basket() -> HashMap<String, u32> {
let mut basket = // TODO: declare your hash map here.
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 here.
basket.insert(String::from("apple"), 4);
basket.insert(String::from("kiwi"), 4);
basket
}

View File

@ -11,8 +11,6 @@
//
// Execute `rustlings hint hashmaps2` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
use std::collections::HashMap;
#[derive(Hash, PartialEq, Eq)]
@ -37,9 +35,11 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
// TODO: Put new fruits if not already present. Note that you
// are not allowed to put any type of fruit that's already
// present!
if let None = basket.get(&fruit) {
basket.insert(fruit, 1);
}
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -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 team name and its goal details.
@ -40,6 +38,24 @@ fn build_scores_table(results: String) -> HashMap<String, Team> {
// will be number of goals conceded from team_2, and similarly
// goals scored by team_2 will be the number of goals conceded by
// team_1.
for team_score in [
(team_1_name, team_1_score, team_2_score),
(team_2_name, team_2_score, team_1_score),
] {
if let Some(team) = scores.get_mut(&team_score.0) {
team.goals_scored = team.goals_scored + team_score.1;
team.goals_conceded = team.goals_conceded + team_score.2;
} else {
scores.insert(
team_score.0.clone(),
Team {
name: team_score.0,
goals_scored: team_score.1,
goals_conceded: team_score.2,
},
);
};
}
}
scores
}

View File

@ -5,8 +5,6 @@
// from the std::time module. Bonus style points if you can do it with one line!
// Execute `rustlings hint modules3` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
// TODO: Complete this use statement
use std::time::{SystemTime, UNIX_EPOCH};