Improve things in main.go

This commit is contained in:
2018-07-07 18:59:15 +01:00
parent b4dde18179
commit 80d00386d4
2 changed files with 59 additions and 42 deletions

28
diffsect.go Normal file
View File

@@ -0,0 +1,28 @@
package main
// diffsect removes all items in `a` from `b`, then removes all items from `b`
// which are not in `c`. Effectively: intersect(difference(b, a), c)
func diffsect(a, b, c *[]string) *[]string {
result := []string{}
mapA := map[string]bool{}
mapC := map[string]bool{}
for _, x := range *a {
mapA[x] = true
}
for _, x := range *c {
mapC[x] = true
}
for _, x := range *b {
_, okA := mapA[x]
_, okC := mapC[x]
if !okA && okC {
result = append(result, x)
}
}
return &result
}