github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/util/collection.go (about) 1 package util 2 3 // Subset returns true if the first slice is completely contained in the second slice 4 func Subset(first, second []string) bool { 5 set := make(map[string]int) 6 for _, value := range second { 7 set[value]++ 8 } 9 10 for _, value := range first { 11 if count, found := set[value]; !found { 12 return false 13 } else if count < 1 { 14 return false 15 } 16 } 17 18 return true 19 } 20 21 // Intersects returns true if any element from the first slice is in the second slice 22 func Intersects(first, second []string) bool { 23 set := make(map[string]int) 24 for _, value := range second { 25 set[value]++ 26 } 27 28 for _, value := range first { 29 if _, found := set[value]; found { 30 return true 31 } 32 } 33 return false 34 } 35 36 func Contains(find string, list []string) bool { 37 var found bool 38 for _, s := range list { 39 if find == s { 40 found = true 41 break 42 } 43 } 44 return found 45 }