I have an array of strings, I need to compare this to another array of strings, but they may be in a different order. What's the best way to compare the two arrays?
This is what I have so far, just wondering if there is a simpler / more efficient way I'm missing.
func unorderedEqual(first, second []string) bool {
if len(first) != len(second) {
return false
}
for _, value := range first {
if !contains(value, second) {
return false
}
}
return true
}
func contains(needle string, haystack []string) bool {
for _, matchValue := range haystack {
if matchValue == needle {
return true
}
}
return false
}