Skip to main content
deleted 27 characters in body
Source Link
Davislor
  • 8.3k
  • 17
  • 37
let separator : &str = if resultaccumulator.is_empty() {
    ""
 } else {
    " "
 };
let separator : &str = if result.is_empty() {
    ""
 } else {
    " "
 };
let separator : &str = if accumulator.is_empty() {""} else {" "};
added 27 characters in body
Source Link
Davislor
  • 8.3k
  • 17
  • 37

What this should do is append the Pig-Latin translation of the word slice to the accumulator string, separated by a space, and return the updated accumulator. (You can move accumulator with let mut result = accumulator; to update it in place, or implement the function without that.) Doing it this way avoids creating or copying any String other than accumulator, which can be moved instead of copied. This can simplify your for loop, but the real benefit of this is that there’s a very elegant abstraction for iterating over a sequence and passing each item to a function like this, then returning the final value.

What this should do is append the Pig-Latin translation of the word slice to the accumulator string, separated by a space, and return the updated accumulator. (You can move accumulator with let mut result = accumulator; to update it in place, or implement the function without that.) Doing it this way avoids creating or copying any String other than accumulator. This can simplify your for loop, but the real benefit of this is that there’s a very elegant abstraction for iterating over a sequence and passing each item to a function like this, then returning the final value.

What this should do is append the Pig-Latin translation of the word slice to the accumulator string, separated by a space, and return the updated accumulator. (You can move accumulator with let mut result = accumulator; to update it in place, or implement the function without that.) Doing it this way avoids creating any String other than accumulator, which can be moved instead of copied. This can simplify your for loop, but the real benefit of this is that there’s a very elegant abstraction for iterating over a sequence and passing each item to a function like this, then returning the final value.

added 64 characters in body
Source Link
Davislor
  • 8.3k
  • 17
  • 37
fn helper(mut accumulator: String, word: &str) -> String

What this should do is append the Pig-Latin translation of the word slice to the accumulator string, separated by a space, and return the updated accumulator. (You could also implement this without acan move accumulator with let mut result = accumulator; accumulatorto update it in place, or implement the function without that.) Doing it this way avoids creating or copying any String other than accumulator. This can simplify your for loop, but the real benefit of this is that there’s a very elegant abstraction for iterating over a sequence and passing each item to a function like this, then returning the final value.

fn helper(mut accumulator: String, word: &str) -> String

What this should do is append the Pig-Latin translation of the word slice to the accumulator string, separated by a space, and return the updated accumulator. (You could also implement this without a mut accumulator.) Doing it this way avoids creating or copying any String other than accumulator. This can simplify your for loop, but the real benefit of this is that there’s a very elegant abstraction for iterating over a sequence and passing each item to a function like this, then returning the final value.

fn helper(accumulator: String, word: &str) -> String

What this should do is append the Pig-Latin translation of the word slice to the accumulator string, separated by a space, and return the updated accumulator. (You can move accumulator with let mut result = accumulator; to update it in place, or implement the function without that.) Doing it this way avoids creating or copying any String other than accumulator. This can simplify your for loop, but the real benefit of this is that there’s a very elegant abstraction for iterating over a sequence and passing each item to a function like this, then returning the final value.

added 9 characters in body
Source Link
Davislor
  • 8.3k
  • 17
  • 37
Loading
added 9 characters in body
Source Link
Davislor
  • 8.3k
  • 17
  • 37
Loading
added 137 characters in body
Source Link
Davislor
  • 8.3k
  • 17
  • 37
Loading
added 70 characters in body
Source Link
Davislor
  • 8.3k
  • 17
  • 37
Loading
Source Link
Davislor
  • 8.3k
  • 17
  • 37
Loading