-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recipe: Reversing an Array has incorrect algorithm #18
Comments
Thanks @pjbgtnj! Working on a test for this now. |
Hey @pjbgtnj - I think you might be incorrect. The existing tests run this code against an odd number of elements and they pass: golangcookbook.github.io/chapters/arrays/reverse/test_copy.go Lines 5 to 18 in c93e83a
Could you possibly attempt a PR where you show this code failing? |
I’m out but will send a test when I get back. For my case the middle element was nil only in the reversed slice of points of length 7. I would have expected your middle element to be 0.
…Sent from my iPhone
On Dec 18, 2019, at 5:21 PM, Tammer Saleh ***@***.***> wrote:
Hey @pjbgtnj - I think you might be incorrect. The existing tests run this code against an odd number of elements and they pass:
https://github.com/superorbital/golangcookbook.github.io/blob/c93e83ac06d037e32126b020980f7a15bd6c58e9/chapters/arrays/reverse/test_copy.go#L5-L18
Could you possibly attempt a PR where you show this code failing?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I just ran the test you provided above and the output is incorrect: [5 4 0 2 1] <<< - The 0 should be a 3 When copying in place the middle most element doesn't need to be swapped but when you copy to a new slice, it does. |
That was right in front of me, and I still didn't see it. Thank you for being persistent :) |
The last example - reversing an array by making a new copy doesn't work if the length of the array is an old number of elements: I'd suggest adding:
or better yet:
The text was updated successfully, but these errors were encountered: