-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhich_in.go
More file actions
40 lines (31 loc) · 810 Bytes
/
which_in.go
File metadata and controls
40 lines (31 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package kata
import (
"sort"
"strings"
)
func RemoveDuplictaesStrings(sl_str []string) []string {
keys := make(map[string]bool)
list := []string{} // = var list []string
//if the key is not equal to the already present value than we append it
for _, entry := range sl_str {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
func InArray(a1 []string, a2 []string) []string {
// sort the two slice of strings
sort.Strings(a1)
sort.Strings(a2)
var r []string
for _, word := range a1 {
for _, w := range a2 {
if strings.Contains(w, word) { // check if a2[w] contains word
r = append(r, word)
}
}
}
return (RemoveDuplictaesStrings(r)) // return the slice whitout repetition
}