Created
December 11, 2019 17:27
-
-
Save akarsh/2e5bff8b957c0cdae980c7ed9bf2d8a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
var testingSet = Set<Int>() | |
// acessing and modifying sets | |
testingSet.insert(1) | |
print(testingSet) | |
print(testingSet.count) | |
print(testingSet.remove(1)) | |
print(testingSet.isEmpty) | |
let evenSet: Set = [0, 2, 4, 8] | |
let oddSet: Set = [1, 3, 5, 7] | |
let primeSet: Set = [2, 3, 5, 7] | |
// union | |
print(evenSet.union(oddSet)) | |
print(evenSet.union(oddSet).sorted()) | |
// intersection | |
print(oddSet.intersection(primeSet)) | |
print(oddSet.intersection(primeSet).sorted()) | |
// subtraction | |
print(primeSet.subtracting(evenSet)) | |
print(primeSet.subtracting(evenSet).sorted()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment