December 2015
Intermediate to advanced
400 pages
13h 3m
English
Functions can serve as arguments to other functions. Recall, for example, that you initially gave sort(_:) the sortAscending(_:j:) 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
var volunteerCounts = [1,3,40,32,2,53,77,13]
let volunteersSorted = volunteerCounts.sort { $0 < $1 }
func makeTownGrand() -> (Int, Int) -> Int {
func buildRoads(lightsToAdd: ...Read now
Unlock full access