mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-05 09:43:31 +02:00
feat(section): hashmap + section complete w/ quiz2
This commit is contained in:
@@ -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