mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Add reverse list
This commit is contained in:
parent
7b096e6013
commit
f45b4f86ca
13
utils.go
13
utils.go
@ -247,3 +247,16 @@ func decodeFromBase32(s string) (s2 string, err error) {
|
||||
s2 = string(bString)
|
||||
return
|
||||
}
|
||||
|
||||
func reverseSliceInt64(s []int64) []int64 {
|
||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
return s
|
||||
}
|
||||
func reverseSliceString(s []string) []string {
|
||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
@ -4,6 +4,16 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReverseList(t *testing.T) {
|
||||
s := []int64{1, 10, 2, 20}
|
||||
if reverseSliceInt64(s)[0] != 20 {
|
||||
t.Errorf("Could not reverse: %v", s)
|
||||
}
|
||||
s2 := []string{"a", "b", "d", "c"}
|
||||
if reverseSliceString(s2)[0] != "c" {
|
||||
t.Errorf("Could not reverse: %v", s2)
|
||||
}
|
||||
}
|
||||
func TestHashing(t *testing.T) {
|
||||
p := HashPassword("1234")
|
||||
log.Debug(p)
|
||||
|
Loading…
Reference in New Issue
Block a user