Skip to content

Instantly share code, notes, and snippets.

@mediocregopher
Last active January 2, 2016 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mediocregopher/8319986 to your computer and use it in GitHub Desktop.
Save mediocregopher/8319986 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type Set map[interface{}]bool
func Intersection(s1, s2 Set) Set {
rs := Set{}
for k := range s1 {
if _, ok := s2[k]; ok {
rs[k] = true
}
}
return rs
}
func main() {
s1 := Set{
1: true,
2: true,
3: true,
"foo": true,
}
s2 := Set{
2: true,
3: true,
4: true,
"foo": true,
}
fmt.Println(Intersection(s1,s2))
}
@mediocregopher
Copy link
Author

outputs:

map[2:true 3:true foo:true]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment