Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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