Skip to content

Instantly share code, notes, and snippets.

@akarsh
Created December 11, 2019 17:27
Show Gist options
  • Save akarsh/2e5bff8b957c0cdae980c7ed9bf2d8a3 to your computer and use it in GitHub Desktop.
Save akarsh/2e5bff8b957c0cdae980c7ed9bf2d8a3 to your computer and use it in GitHub Desktop.
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