blob: a7e6c3d6b65082244d6a1a822ea678a7ad99e028 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#[derive(Debug)]
pub struct HighScores<'a> {
scores: &'a [u32]
}
impl<'a> HighScores<'a> {
pub fn new(scores: &'a [u32]) -> Self {
HighScores{ scores }
}
pub fn scores(&self) -> &[u32] {
self.scores
}
pub fn latest(&self) -> Option<u32> {
self.scores.last().copied()
}
pub fn personal_best(&self) -> Option<u32> {
self.scores.iter().max().copied()
}
pub fn personal_top_three(&self) -> Vec<u32> {
let mut top3 = self.scores.to_vec();
top3.sort_unstable_by(|a,b| b.cmp(a));
top3.truncate(3);
top3
}
}
|