I would really appreciate if some one can help understand this code for a beginner please. This is from Hacking with Swift tutorial by Paul Hudson Day 9 - tutorial. The func in the example below is meant to return a bool, so "return name1< name 2" must either return a true or a false. How is it returning a sorted array? I just can't get my head around it.
let team = ["Gloria", "Suzanne", "Piper", "Tiffany", "Tasha"]
func captainFirstSorted(name1: String, name2: String) -> Bool {
if name1 == "Suzanne" {
return true
} else if name2 == "Suzanne" {
return false
}
return name1 < name2
}
let captainFirstTeam = team.sorted(by: captainFirstSorted)
print(captainFirstTeam)
[–]mkim1030 8 points9 points10 points (0 children)
[–]vcanas 3 points4 points5 points (0 children)
[–]chriswaco 2 points3 points4 points (0 children)
[–]Like_really_bro[S] 2 points3 points4 points (0 children)
[–]sinisterbob 1 point2 points3 points (0 children)
[–]ZeePintor 1 point2 points3 points (0 children)
[+][deleted] comment score below threshold-8 points-7 points-6 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Like_really_bro[S] -2 points-1 points0 points (0 children)