Logo

Programming-Idioms

History of Idiom 19 > diff from v1 to v2

Edit summary for version 2 by :

Version 1

2015-05-06, 21:04:49

Version 2

2015-07-10, 08:01:58

Idiom #19 Reverse a list

Reverse the order of the elements of list x .
This may reverse "in-place" and destroy the original ordering.

Idiom #19 Reverse a list

Reverse the order of the elements of list x .
This may reverse "in-place" and destroy the original ordering.

Code
for i, j := 0, len(x)-1; i < j; i, j = i+1, j-1 {
	x[i], x[j] = x[j], x[i]
}
Code
for i, j := 0, len(x)-1; i < j; i, j = i+1, j-1 {
	x[i], x[j] = x[j], x[i]
}
Comments bubble
This loop reverts "in-place" (in the original list, not creating a new one).
Origin
http://stackoverflow.com/a/19239850/871134
Origin
http://stackoverflow.com/a/19239850/871134
Demo URL
http://play.golang.org/p/vkJg_D1yUb
Demo URL
http://play.golang.org/p/vkJg_D1yUb