I'm confused here too - is there some other desired behavior? I thought the goal here was to avoid race conditions and just reproduce that order, since that's what's in the source code...
> var buttons = []string{"red", "blue", "green", "yellow", "purple"}
There are none, right? So even if you add mutexes to the existing code in an attempt to remove race conditions, it will still have race conditions, and have no guaranteed output order, because you have no guarantee which order the goroutines will start in.
The obvious way to solve it in order to get the answer shown in the source code is
if x == 0 {
*sequence = []Button{{"red"}, {"blue"}, {"green"}, {"yellow"}, {"purple"}}
}
return
This way there is nothing concurrently touching sequence, nor is there anything concurrent touching rand, nor is anything relying on goroutine starting order, nor are there other race conditions. But yet the site says this is wrong.
Yeah I know about the hint. But the result the hint leads you to doesn't make sense. Using a Mutex removes data races, but it does not remove race conditions. By leaving the race condition in, the code is has output that cannot be relied on. But yet the challenge wants us to think that somehow the output has a specific value that can be relied on.