Skip to content

Add challenge solutions #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions 5-arrays-and-sets/school-roster/Roster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,61 @@ for aClass in classSet {
}
print ("There are \(sevenPlus) classes with seven or more students.")



// Task Group: Challenge #1

// Use `.remove()` to delete Skyla from any classes they are currently enrolled in.
spanish101.remove("Skyla")
artHistory.remove("Skyla")
computerScience.remove("Skyla")

// Create updated set of class rosters
var newClassSet: Set = [spanish101, german101, englishLiterature, computerScience, artHistory, advancedCalculus]

print("New Class Rosters:")
for aClass in newClassSet {
print(aClass)
}



// Task Group: Challenge #2

// Create a set called `fieldTrip` that combines these two sets using `.union()`
var fieldTrip = Set<String>(computerScience.union(advancedCalculus))

print("Field Trip Group:")
print(fieldTrip)



// Task Group: Challenge #3

// Use `.subtracting()` to remove any students in `fieldTrip` who are also in `german101`
fieldTrip = fieldTrip.subtracting(german101)
print("Updated Field Trip Group:")
print(fieldTrip)



// Alternate for-loop solution for Challenge #1
// Note: using this will not remove Skyla from the individual class sets (e.g., `computerScience`)
// Uncomment the code block below to try it out:
/*
var updatedClassSet = Set<Set<String>>()
for var innerSet in classSet {
if innerSet.contains("Skyla") {
innerSet.remove("Skyla")
updatedClassSet.insert(innerSet)
} else {
// If "Skyla" is not in the innerSet, insert to updatedClassSet as-is
updatedClassSet.insert(innerSet)
}
}

print("New Class Rosters:")
for aClass in updatedClassSet {
print(aClass)
}
*/