summaryrefslogtreecommitdiff
path: root/solutions/quizzes/quiz2.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-07-07 20:28:31 +0200
committermo8it <mo8it@proton.me>2024-07-07 20:28:31 +0200
commit0f4cb94cfe31745e8fee9efc7dc1d287e65e16cb (patch)
treeef5c5fc78f66b71cc3eab9ff913ad43b6591d1b4 /solutions/quizzes/quiz2.rs
parent6469e9734b47d2a34ad3aeaa4e7c68c7ca679f00 (diff)
quiz2: Use repeat
Diffstat (limited to 'solutions/quizzes/quiz2.rs')
-rw-r--r--solutions/quizzes/quiz2.rs11
1 files changed, 3 insertions, 8 deletions
diff --git a/solutions/quizzes/quiz2.rs b/solutions/quizzes/quiz2.rs
index be3f159..2f55f06 100644
--- a/solutions/quizzes/quiz2.rs
+++ b/solutions/quizzes/quiz2.rs
@@ -24,17 +24,12 @@ mod my_module {
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
let mut output = Vec::new();
- for (mut string, command) in input {
+ for (string, command) in input {
// Create the new string.
let new_string = match command {
Command::Uppercase => string.to_uppercase(),
Command::Trim => string.trim().to_string(),
- Command::Append(n) => {
- for _ in 0..n {
- string += "bar";
- }
- string
- }
+ Command::Append(n) => string + &"bar".repeat(n),
};
// Push the new string to the output vector.
@@ -49,7 +44,7 @@ mod my_module {
pub fn transformer_iter(input: Vec<(String, Command)>) -> Vec<String> {
input
.into_iter()
- .map(|(mut string, command)| match command {
+ .map(|(string, command)| match command {
Command::Uppercase => string.to_uppercase(),
Command::Trim => string.trim().to_string(),
Command::Append(n) => string + &"bar".repeat(n),