feat:完善项目

This commit is contained in:
henry
2021-11-16 11:46:44 +08:00
parent 78128277ff
commit 978918e5aa
14 changed files with 193 additions and 19 deletions

View File

@ -49,3 +49,24 @@ func ArrayStrings(src interface{}) []string {
}
return out
}
func ArrayUnique(src interface{}) []interface{} {
val := reflect.ValueOf(src)
kind := val.Kind()
out := make([]interface{}, 0)
if kind == reflect.Slice || kind == reflect.Array {
for i := 0; i < val.Len(); i++ {
for _, v := range out {
if v == val.Index(i).Interface() {
goto BREAK
}
}
out = append(out, val.Index(i).Interface())
BREAK:
}
}
return out
}

View File

@ -38,3 +38,13 @@ func TestArrayStrings(t *testing.T) {
t.Log(b)
t.Log(reflect.TypeOf(b).String())
}
func TestArrayUnique(t *testing.T) {
a := []uint64{1, 2, 3, 4, 5, 5, 5}
b := ArrayUnique(a)
t.Log(b)
for _, v := range b {
fmt.Printf(reflect.TypeOf(v).String())
}
}