Initial commit

This commit is contained in:
2022-08-04 23:58:25 +02:00
commit ff1c36fc24
447 changed files with 9869 additions and 0 deletions

31
high-scores/src/lib.rs Normal file
View File

@@ -0,0 +1,31 @@
#[derive(Debug)]
pub struct HighScores<'a> {
scores: &'a [u32]
}
impl<'a> HighScores<'a> {
pub fn new(scores: &'a [u32]) -> Self {
Self {
scores
}
}
pub fn scores(&self) -> &[u32] {
self.scores
}
pub fn latest(&self) -> Option<u32> {
self.scores.last().cloned()
}
pub fn personal_best(&self) -> Option<u32> {
self.scores.iter().max().cloned()
}
pub fn personal_top_three(&self) -> Vec<u32> {
let mut top_vec = self.scores.to_vec();
top_vec.sort_unstable_by(|a, b| b.cmp(a));
top_vec.truncate(3);
top_vec
}
}