You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
887 B

2 years ago
package xarray
import (
"reflect"
"strings"
)
func ToSlice(slice interface{}) []interface{} {
s := reflect.ValueOf(slice)
if s.Kind() != reflect.Slice {
panic("InterfaceSlice() given a non-slice type")
}
ret := make([]interface{}, s.Len())
for i := 0; i < s.Len(); i++ {
ret[i] = s.Index(i).Interface()
}
return ret
}
func ToCountMap(strArr []string) map[string]int64 {
mps := make(map[string]int64)
for _, v := range strArr {
mps[strings.ToLower(v)]++
}
return mps
}
func InArray(need interface{}, list []interface{}) bool {
for _, v := range list {
if need == v {
return true
}
}
return false
}
func UniqArray(list []int64) []int64 {
result := make([]int64, 0)
if len(list) == 0 {
return result
}
mp := make(map[int64]bool)
for _, v := range list {
if mp[v] {
continue
}
result = append(result, v)
mp[v] = true
}
return result
}