November 2016
Intermediate to advanced
480 pages
14h 42m
English
Functions can serve as arguments to other functions. Recall, for example, that you initially gave sorted(by:) the sortAscending(_:_:) function as an argument.
Practicality suggests that your town can only build roads when it has a suitable budget. Adjust your previous makeTownGrand() function to take a budget parameter and a condition parameter. The budget parameter will serve as your town’s budget, and the condition parameter will evaluate whether this budget is suitable to build the new roads.
Listing 13.9 Adding budget considerations
import Cocoa
let volunteerCounts = [1,3,40,32,2,53,77,13]
let volunteersSorted = volunteerCounts.sorted { $0 < $1 }
func makeTownGrand() -> (Int, Int) -> Int {
func buildRoads(byAddingLights ...Read now
Unlock full access