Created
January 3, 2016 05:11
-
-
Save mattyoung/b7cae1c39d7d0f21fae6 to your computer and use it in GitHub Desktop.
weheartswift.com Dictionary Excercise 11.6 Leaderboard with struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Person { | |
let firstName: String | |
let lastName: String | |
let score: Int | |
} | |
var people: [Person] = [ | |
Person( | |
firstName: "Calvin", | |
lastName: "Newton", | |
score: 13 | |
), | |
Person( | |
firstName: "Garry", | |
lastName: "Mckenzie", | |
score: 23 | |
), | |
Person( | |
firstName: "Leah", | |
lastName: "Rivera", | |
score: 10 | |
), | |
Person( | |
firstName: "Sonja", | |
lastName: "Moreno", | |
score: 3 | |
), | |
Person( | |
firstName: "Noel", | |
lastName: "Bowen", | |
score: 16 | |
) | |
] | |
func >(lhs: Person, rhs: Person) -> Bool { | |
return lhs.score > rhs.score | |
} | |
people.sortInPlace(>) | |
for (index, person) in people.enumerate() { | |
print("\(index + 1). \(person.firstName) \(person.lastName) - \(person.score).") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment