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.