Skip to content

Commit

Permalink
up: rename str convert to conv.go
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 4, 2022
1 parent 01f229c commit baae69d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions arrutil/arrutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func StringsMap(ss []string, mapFn func(s string) string) []string {
//
// // output: [a, b, c]
// ss := arrutil.TrimStrings([]string{",a", "b.", ",.c,"}, ",.")
func TrimStrings(ss []string, cutSet ...string) (ns []string) {
func TrimStrings(ss []string, cutSet ...string) []string {
cutSetLn := len(cutSet)
hasCutSet := cutSetLn > 0 && cutSet[0] != ""

Expand All @@ -80,14 +80,15 @@ func TrimStrings(ss []string, cutSet ...string) (ns []string) {
trimSet = strings.Join(cutSet, "")
}

ns := make([]string, 0, len(ss))
for _, str := range ss {
if hasCutSet {
ns = append(ns, strings.Trim(str, trimSet))
} else {
ns = append(ns, strings.TrimSpace(str))
}
}
return
return ns
}

// GetRandomOne get random element from an array/slice
Expand All @@ -104,3 +105,16 @@ func RandomOne(arr interface{}) interface{} {
r := rv.Index(i).Interface()
return r
}

// Unique value in the given array, slice.
func Unique(arr interface{}) interface{} {
rv := reflect.ValueOf(arr)
if rv.Kind() != reflect.Slice && rv.Kind() != reflect.Array {
return arr
}

for i := 0; i < rv.Len(); i++ {
// TODO ...
}
return arr
}
File renamed without changes.
File renamed without changes.

0 comments on commit baae69d

Please sign in to comment.