diff --git a/src/lib.rs b/src/lib.rs index 0a8a821..99789e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,11 @@ pub fn build_proverb(list: &[&str]) -> String { let mut verse = "".to_string(); - if !list.is_empty() { + if let Some(nail) = list.first() { for item in list.windows(2) { verse.push_str(&format!("For want of a {} the {} was lost.\n", item[0], item[1])); } - verse.push_str(&format!("And all for the want of a {}.", list[0])); + verse.push_str(&format!("And all for the want of a {}.", nail)); } verse