Skip to content

Commit

Permalink
add some func
Browse files Browse the repository at this point in the history
  • Loading branch information
UlricQin committed Jul 20, 2019
1 parent 157c3e6 commit 7edfbde
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions slice/contains.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ func ContainsString(sl []string, v string) bool {
}
return false
}


func ContainsSlice(smallSlice, bigSlice []string) bool {
for i := 0; i < len(smallSlice); i++ {
if !ContainsString(smallSlice[i], bigSlice) {
return false
}
}

return true
}
29 changes: 29 additions & 0 deletions slice/unique.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package slice

import "strings"

func UniqueInt64(s []int64) []int64 {
size := len(s)
if size == 0 {
Expand Down Expand Up @@ -68,3 +70,30 @@ func UniqueString(s []string) []string {

return ret
}

func UniqueTrimString(s []string) []string {
size := len(s)
if size == 0 {
return []string{}
}

m := make(map[string]struct{})
for i := 0; i < size; i++ {
item := strings.TrimSpace(s[i])
if item == "" {
continue
}
m[item] = struct{}{}
}

realLen := len(m)
ret := make([]string, realLen)

idx := 0
for key := range m {
ret[idx] = key
idx++
}

return ret
}

0 comments on commit 7edfbde

Please sign in to comment.