.symmetricDifference() operation can be used to find elements that exist in one of the given sets, but not both.
The syntax for creating a set using
.symmetricDifference() looks like this:
var NewSet = SetA.symmetricDifference(SetB)
The following sets
String values of games that can be played on that specific console:
var nintendoSwitch: Set = ["Animal Crossing", "DOOM Eternal", "Stardew Valley"] var playStation4: Set = ["DOOM Eternal", "Stardew Valley", "The Last of Us"]
To find which games are exclusive to only one console, we can use
.symmeticDifference() to remove any values that appear in both
var exclusiveGames = nintendoSwitch.symmetricDifference(playStation4)
print() the values contained within
exclusiveGames, we would get something similar to the following output:
["Animal Crossing", "The Last of Us"]
Take a look at the two sets
emmyWinners in Awards.swift.
.symmetricDifference() to create a set called
difference that contains the values that appear in either
emmyWinners but do not appear in both sets.
Print the value of