# Challenge Solutions for Sets

Here are the solutions I came up with…these were easy, eh?

let myCities: Set = ["Atlanta", "Chicago", "Jacksonville", "New York", "San Francisco"]

let yourCities: Set = ["Chicago", "San Francisco", "Jacksonville"]

let isSuperSet = myCities.isSuperset(of: yourCities)

friendsGroceryBag.formUnion(groceryBag)

commonGroceryBag.formIntersection(roommatesGroceryBag)

alternatively:

let myCities = Set(["Atlanta", "Chicago", "Jacksonville", "New York", "San Francisco"])
let yourCities = Set(["Atlanta", "Jacksonville", "San Francisco"])
let areDisjointed = yourCities.isDisjoint(with: yourCities.intersection(myCities))

It’s worth noting that isDisjoint implies a complete disjoint. So if you were to change Atlanta to Seattle in the yourCities list, the expression would still return a false, since there was still an intersection on Jacksonville and San Francisco.

1 Like

Bronze Challenge
Step 1. Input

let myCities = Set(["Atlanta", "Chicago", "Jacksonville", "New York","San Francisco"])
let yourCities = Set(["Chicago", " San Francisco", "Jacksonville"])
let sameCities = myCities.isSuperset(of: yourCities)
// Output is false

Silver Challenge
Step 1. From the “Unions” Section make sure to update commonGroceryBag to “var”

let friendsGroceryBag = Set(["Bananas", "Cereal", "Milk", "Oranges"])
var commonGroceryBag = groceryBag.union(friendsGroceryBag)

Step 2. Input

groceryBag.formUnion(friendsGroceryBag)

commonGroceryBag.formIntersection(roommatesGroceryBag)
// Output is Bananas, Cereal, Apples