utils/comparisons.go

21 lines
605 B
Go
Raw Normal View History

2024-06-04 21:41:28 +02:00
package utils
// GetUniqueElementsOfStringSlices finds the elements that are in the first slice but not in the second slice
func GetUniqueElementsOfStringSlices(a, b []string) []string {
// Create a map to store the elements of "b"
mapOfElementsOfSliceB := make(map[string]bool)
for _, e := range b {
mapOfElementsOfSliceB[e] = true
}
// Iterate through "a" and find the elements that are not in "b"
var uniqueElementsOfSliceA []string
for _, e := range a {
if !mapOfElementsOfSliceB[e] {
uniqueElementsOfSliceA = append(uniqueElementsOfSliceA, e)
}
}
return uniqueElementsOfSliceA
}