Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
(def c (clojure.set/intersection (set a) (set b)))
C = lists:flatten([A -- B] ++ [B -- A]).
func intersection[S ~[]T, T comparable](a, b S) S {
s, l := a, b
if len(b) < len(a) {
s, l = b, a
}
set := make(map[T]struct{}, len(s))
for _, x := range s {
set[x] = struct{}{}
}
c := make(S, 0, len(s))
for _, x := range l {
if _, found := set[x]; found {
c = append(c, x)
delete(set, x)
}
}
return c
}
func intersection[S ~[]T, T comparable](a, b S) S {
seta := make(map[T]bool, len(a))
for _, x := range a {
seta[x] = true
}
setb := make(map[T]bool, len(b))
for _, y := range b {
setb[y] = true
}
var c S
for x := range seta {
if setb[x] {
c = append(c, x)
}
}
return c
}
seta := make(map[T]bool, len(a))
for _, x := range a {
seta[x] = true
}
setb := make(map[T]bool, len(a))
for _, y := range b {
setb[y] = true
}
var c []T
for x := range seta {
if setb[x] {
c = append(c, x)
}
}
const c = [...new Set(a)].filter(e => b.includes(e));
$c = array_intersect($a, $b)
my %u;
$u{$_} = 1 for @a, @b;
my @c = keys %u;
c = list(set(a) & set(b))
c = list(set(a).intersection(b))
c = a & b