Refactor note_ease_str()
This commit is contained in:
parent
d7da1c1578
commit
31155f2dcd
@ -466,17 +466,18 @@ impl<'a> NoteRowContext<'a> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the average ease of the non-new cards or a hint if there aren't any.
|
||||||
fn note_ease_str(&self) -> String {
|
fn note_ease_str(&self) -> String {
|
||||||
let cards = self
|
let eases: Vec<u16> = self
|
||||||
.cards
|
.cards
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|c| c.ctype != CardType::New)
|
.filter(|c| c.ctype != CardType::New)
|
||||||
.collect::<Vec<&Card>>();
|
.map(|c| c.ease_factor)
|
||||||
if cards.is_empty() {
|
.collect();
|
||||||
|
if eases.is_empty() {
|
||||||
self.tr.browsing_new().into()
|
self.tr.browsing_new().into()
|
||||||
} else {
|
} else {
|
||||||
let ease = cards.iter().map(|c| c.ease_factor).sum::<u16>() / cards.len() as u16;
|
format!("{}%", eases.iter().sum::<u16>() / eases.len() as u16 / 10)
|
||||||
format!("{}%", ease / 10)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user