Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
saiyuan233 committed Dec 24, 2024
1 parent b8b8305 commit 40bb999
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion exercises/hashmaps/hashmaps2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Execute `rustlings hint hashmaps2` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE


use std::collections::HashMap;

Expand All @@ -40,6 +40,7 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
// 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(10);
}
}

Expand Down
15 changes: 14 additions & 1 deletion exercises/hashmaps/hashmaps3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Execute `rustlings hint hashmaps3` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE


use std::collections::HashMap;

Expand All @@ -39,6 +39,19 @@ 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.
let score = scores.entry(team_1_name.clone()).or_insert(Team{
goals_scored: 0,
goals_conceded: 0
});
(*score).goals_scored += team_1_score;
(*score).goals_conceded += team_2_score;

let score = scores.entry(team_2_name.clone()).or_insert(Team{
goals_scored: 0,
goals_conceded: 0
});
(*score).goals_scored += team_2_score;
(*score).goals_conceded += team_1_score;
}
scores
}
Expand Down
18 changes: 15 additions & 3 deletions exercises/quiz2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@ mod my_module {
use super::Command;

// TODO: Complete the function signature!
pub fn transformer(input: ???) -> ??? {
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
// TODO: Complete the output declaration!
let mut output: ??? = vec![];
let mut output: Vec<String> = vec![];
for (string, command) in input.iter() {
// TODO: Complete the function body. You can do it!
let transformer_string = match command {
Command::Uppercase => string.to_uppercase(),
Command::Trim => string.trim().to_string(),
Command::Append(n) => {
let mut s = String::from(string);
for _ in 0..*n {
s.push_str("bar");
}
s.to_string()
}
};
output.push(transformer_string);
}
output
}
Expand All @@ -45,7 +57,7 @@ mod my_module {
#[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]
Expand Down

0 comments on commit 40bb999

Please sign in to comment.