Trying to combine multiple slices using variadic, I'm getting error: cannot initialize 2 variables with 1 value
How do I call this Combine function?
Here's the code:
func Combine(ss ...[]string) []string {
mp := map[string]bool{}
for _, s := range ss {
for _, v := range s {
if v != "" {
if _, ok := mp[v]; !ok {
mp[v] = true
}
}
}
}
combined := []string{}
for v := range mp {
combined = append(combined, v)
}
return combined
}
tests := []struct {
caseName string
s1 []string
s2 []string
want []string
}{
{
caseName: "Test combining 2 slices",
s1: []string{"a", "b", "c", "c", ""},
s2: []string{"a", "b", "z", "z", "", "y"},
want: []string{"a", "b", "c", "y", "z"},
},
}
actual, _ := Combine(test.s1, test.s2)