Current progress
This commit is contained in:
@@ -10,17 +10,18 @@
|
||||
//
|
||||
// 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();// TODO: declare your hash map here.
|
||||
|
||||
// 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"), 1);
|
||||
basket.insert(String::from("orange"), 2);
|
||||
|
||||
basket
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -37,6 +36,7 @@ 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!
|
||||
basket.entry(fruit).or_insert(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
// Execute `rustlings hint hashmaps3` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -40,6 +39,26 @@ fn build_scores_table(results: String) -> HashMap<String, Team> {
|
||||
// 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())
|
||||
.and_modify(|e| {
|
||||
e.goals_scored += team_1_score;
|
||||
e.goals_conceded += team_2_score;
|
||||
})
|
||||
.or_insert(Team {
|
||||
name: team_1_name,
|
||||
goals_scored: team_1_score,
|
||||
goals_conceded: team_2_score,
|
||||
});
|
||||
scores.entry(team_2_name.clone())
|
||||
.and_modify(|e| {
|
||||
e.goals_scored += team_2_score;
|
||||
e.goals_conceded += team_1_score;
|
||||
})
|
||||
.or_insert(Team {
|
||||
name: team_2_name,
|
||||
goals_scored: team_2_score,
|
||||
goals_conceded: team_1_score,
|
||||
});
|
||||
}
|
||||
scores
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user