Kodewick
Start learning →
Mini challenge←→0 / 70

Merge guest lists

#030Mini challengeSlicesLoops7 min

You and a friend each wrote a party guest list. Write MergeGuests(mine, yours): your list first, then everyone from your friend's list who isn't on it yet, in their order. Neither list repeats a name on its own, and either may be empty.

Examples
MergeGuests([]string{"Ana", "Ben"}, []string{"Ben", "Cai"})→['Ana', 'Ben', 'Cai']
MergeGuests([]string{}, []string{"Dee"})→['Dee']
The functionfunc MergeGuests(mine, yours []string) []string
main.go
package main

func MergeGuests(mine, yours []string) []string {
	guests := []string{}
	guests = append(guests, mine...)
	for _, name := range yours {
		found := false
		// your code here: look for name in guests; found it? set found to true
		// your code here: not found? append name to guests
	}
	return guests
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.