go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/utils/stringx/intersection.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package stringx
     5  
     6  func Intersection(a, b []string) []string {
     7  	entriesMap := map[string]struct{}{}
     8  	res := []string{}
     9  
    10  	for i := range a {
    11  		entriesMap[a[i]] = struct{}{}
    12  	}
    13  
    14  	for i := range b {
    15  		if _, ok := entriesMap[b[i]]; ok {
    16  			res = append(res, b[i])
    17  		}
    18  	}
    19  	return res
    20  }