Skip to content

Commit 6f931d9

Browse files
committed
Implement Reverse function for bytes slice
The function can be used to reverse the bytes order in the slice.
1 parent 1c2eee0 commit 6f931d9

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

pkg/internal/byteutils/byteutils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ func LeftPadTo32Bytes(bytes []byte) ([]byte, error) {
2222

2323
return result, nil
2424
}
25+
26+
// Reverse reverses bytes order in the slice.
27+
func Reverse(bytes []byte) []byte {
28+
result := make([]byte, 0, len(bytes))
29+
for i := len(bytes) - 1; i >= 0; i-- {
30+
result = append(result, bytes[i])
31+
}
32+
return result
33+
}

0 commit comments

Comments
 (0)