diff --git a/chapters/arrays/reverse/index.md b/chapters/arrays/reverse/index.md index a3add43..922ef5a 100644 --- a/chapters/arrays/reverse/index.md +++ b/chapters/arrays/reverse/index.md @@ -9,28 +9,26 @@ in turn with its mirror counterpart: {%include example.html example="simple"%} -There's an even more terse implementation which makes use of the `,` operator +There's an even more concise implementation that uses the `,` operator inside the Go for loop: {%include example.html example="terse"%} -Note that both of these `reverse` functions take slices, which are passed by -value. This is good for performance, but means we're actually modifying the -passed in array, leading to unexpected results. In other words, the `reverse` +Note that both of these `reverse` functions take slices, which are passed by reference. +This is good for performance, but means we're actually modifying the +passed in array, this might not be the intended behavior. In other words, the `reverse` method could be written like such: {%include example.html example="alternate"%} Now `reverse` doesn't return another reference to the slice, which makes it -much more clear that it's modifying the slice in-place. If we want to return a -modified copy of the slice, we must do so manually: +much more clear that it's modifying the slice in-place. If you want to return a +modified copy of the slice without altering the original, you need to create +and return a new slice manually: {%include example.html example="copy"%} -As you can see in the output above, the original array is untouched. - -Since we're not modifying the array in-place, we can also simplify our -algorithm buy doing a more straight-forward element copy: +This ensures the original array remains untouched. +You can also simplify the algorithm by directly copying elements into a new slice: {%include example.html example="copy_simple"%} -