21 lines
605 B
Go
21 lines
605 B
Go
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
|
|
}
|