Skip to content

Instantly share code, notes, and snippets.

@mattyoung
Created January 3, 2016 05:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattyoung/b7cae1c39d7d0f21fae6 to your computer and use it in GitHub Desktop.
Save mattyoung/b7cae1c39d7d0f21fae6 to your computer and use it in GitHub Desktop.
weheartswift.com Dictionary Excercise 11.6 Leaderboard with struct
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