feat:完善信息
This commit is contained in:
@ -5,16 +5,34 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// [1,2,3, 4, 5,6,7]
|
||||
// 7
|
||||
// mid: 3
|
||||
func InArray(search, needle interface{}) bool {
|
||||
val := reflect.ValueOf(needle)
|
||||
|
||||
kind := val.Kind()
|
||||
|
||||
if kind == reflect.Slice || kind == reflect.Array {
|
||||
for i := 0; i < val.Len(); i++ {
|
||||
_length := val.Len()
|
||||
|
||||
if _length <= 0 {
|
||||
return false
|
||||
} else if _length == 1 {
|
||||
return val.Index(0).Interface() == search
|
||||
}
|
||||
mid := _length >> 1
|
||||
|
||||
for i := 0; i < mid; i++ {
|
||||
if val.Index(i).Interface() == search {
|
||||
return true
|
||||
}
|
||||
if val.Index((_length-1)-i).Interface() == search {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if _length%2 > 0 {
|
||||
return val.Index(mid+1).Interface() == search
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
Reference in New Issue
Block a user