exercism/dart/high-scores/lib/high_scores.dart

23 lines
447 B
Dart

class HighScores {
List<int> scores = <int>[];
HighScores(List<int> s) {
scores = s;
}
int latest() => scores.last;
int personalBest() => _sorted().first;
List<int> personalTopThree() {
List<int> wrk = _sorted();
if(wrk.length >= 3) {
return wrk.sublist(0, 3);
}
return wrk;
}
List<int> _sorted() {
List<int> wrk = List.of(scores);
wrk.sort((e1, e2) => e2.compareTo(e1));
return wrk;
}
}