2019-02-25 22:44:14 +00:00
|
|
|
package slice
|
|
|
|
|
2019-03-17 18:26:35 +00:00
|
|
|
// Reverse return a reversed version of the given byte slice.
|
2019-02-25 22:44:14 +00:00
|
|
|
func Reverse(b []byte) []byte {
|
|
|
|
// Protect from big.Ints that have 1 len bytes.
|
|
|
|
if len(b) < 2 {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
dest := make([]byte, len(b))
|
|
|
|
for i, j := 0, len(b)-1; i < j+1; i, j = i+1, j-1 {
|
|
|
|
dest[i], dest[j] = b[j], b[i]
|
|
|
|
}
|
|
|
|
return dest
|
|
|
|
}
|