From 31155f2dcdf05f0da52dbad434d5a944fb694728 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Tue, 30 Mar 2021 23:44:16 +0200 Subject: [PATCH] Refactor note_ease_str() --- rslib/src/browser_table.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rslib/src/browser_table.rs b/rslib/src/browser_table.rs index 3c3a1c594..a8d1bf5c5 100644 --- a/rslib/src/browser_table.rs +++ b/rslib/src/browser_table.rs @@ -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 { - let cards = self + let eases: Vec = self .cards .iter() .filter(|c| c.ctype != CardType::New) - .collect::>(); - if cards.is_empty() { + .map(|c| c.ease_factor) + .collect(); + if eases.is_empty() { self.tr.browsing_new().into() } else { - let ease = cards.iter().map(|c| c.ease_factor).sum::() / cards.len() as u16; - format!("{}%", ease / 10) + format!("{}%", eases.iter().sum::() / eases.len() as u16 / 10) } }