Skip to content

Commit 0f4cb94

Browse files
committed
quiz2: Use repeat
1 parent 6469e97 commit 0f4cb94

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

solutions/quizzes/quiz2.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@ mod my_module {
2424
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
2525
let mut output = Vec::new();
2626

27-
for (mut string, command) in input {
27+
for (string, command) in input {
2828
// Create the new string.
2929
let new_string = match command {
3030
Command::Uppercase => string.to_uppercase(),
3131
Command::Trim => string.trim().to_string(),
32-
Command::Append(n) => {
33-
for _ in 0..n {
34-
string += "bar";
35-
}
36-
string
37-
}
32+
Command::Append(n) => string + &"bar".repeat(n),
3833
};
3934

4035
// Push the new string to the output vector.
@@ -49,7 +44,7 @@ mod my_module {
4944
pub fn transformer_iter(input: Vec<(String, Command)>) -> Vec<String> {
5045
input
5146
.into_iter()
52-
.map(|(mut string, command)| match command {
47+
.map(|(string, command)| match command {
5348
Command::Uppercase => string.to_uppercase(),
5449
Command::Trim => string.trim().to_string(),
5550
Command::Append(n) => string + &"bar".repeat(n),

0 commit comments

Comments
 (0)