dart-exercism/high-scores/lib/high_scores.dart
2024-10-14 11:37:17 +02:00

16 lines
347 B
Dart

class HighScores {
List<int> scores;
late List<int> sortedScores;
HighScores([this.scores = const [0]]) {
sortedScores = scores.toList();
sortedScores.sort((a, b) => b.compareTo(a));
}
int latest() => scores.last;
Iterable<int> personalTopThree() => this.sortedScores.take(3);
int personalBest() => sortedScores.first;
}