Bronze Challenge...did I do the Silver Challenge instead?

If I can sort the collection in place, then I need to change make the array mutable. Ergo, change ‘let’ to ‘var’.

Auto-complete in Xcode brought me to a sort(by:) method. But I’m not sure if they’re looking for the below as part of the Silver Challenge:

// bronze challenge: sort this collection in place -- without returning a new one
var volunteerCounts = [1,3,40,32,2,53,77,13]

print(volunteerCounts[volunteerCounts.count - 1]) // 13
volunteerCounts.sort(by: {$0 < $1})
print(volunteerCounts) // [1, 2, 3, 13, 32, 40, 53, 77]
print(volunteerCounts[volunteerCounts.count - 1]) // 77

That’s not what they’re looking for, though sorting the array in-place is fine. For the SIlver challenge, they’re looking for something simpler than using sort(by:).

Something simpler than



No, I think


is exactly what they are looking for. They want you to figure out that sort() will do an ascending sort by default (assuming the values in the array have the appropriate comparison functions) so you don’t need to pass in an enclosure to get that result.

1 Like

Cool! Thanks. Now onto this Gold Challenge.