mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-01 07:53:30 +02:00
feat(section): hashmap + section complete w/ quiz2
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<String> {
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user