Last active
August 14, 2020 19:48
-
-
Save montyr75/1f74cee222fe5b9b3381d30a074a5687 to your computer and use it in GitHub Desktop.
Sort by multiple factors.
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
String meeting(String s) { | |
final people = s.split(';').map((String name) => Person.fromData(name)).toList(); | |
people.sort(); | |
return people.join(); | |
} | |
class Person implements Comparable<Person> { | |
final firstName; | |
final lastName; | |
const Person(this.firstName, this.lastName); | |
factory Person.fromData(String data) { | |
final splitData = data.toUpperCase().split(':'); | |
return Person(splitData.first, splitData.last); | |
} | |
int compareTo(Person other) { | |
final result = lastName.compareTo(other.lastName); | |
return result == 0 ? firstName.compareTo(other.firstName) : result; | |
} | |
@override | |
String toString() => "($lastName, $firstName)"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment