Let's take a look at what this looks like in practice. We can use some of the techniques we learned in this chapter to write a different and possibly better implementation of our party inviter.
We can start by defining the same input data:
//: List of people to invite let invitees = [ "Sarah", "Jamison", "Marcos", "Roana", "Neena", ] //: Dictionary of shows organized by genre var showsByGenre = [ "Comedy": "Modern Family", "Drama": "Breaking Bad", "Variety": "The Colbert Report", ]
In this implementation, we are making the invitees list, which is just a constant list of names and the shows by genre dictionary variable. This is because we are going to be mapping our invitees list to a list of invitation text. As we do the mapping, we will have to pick a random genre to assign to the current invitee, and in order to avoid assigning the same genre more than once, we can remove the genre from the dictionary.
So let's write the random genre
function:
func pickAndRemoveRandomGenre...