proverb
This commit is contained in:
parent
ed09dd5590
commit
d5f25bd8bf
7 changed files with 276 additions and 0 deletions
14
rust/proverb/src/lib.rs
Normal file
14
rust/proverb/src/lib.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
pub fn build_proverb(list: &[&str]) -> String {
|
||||
if list.is_empty() {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
list.windows(2)
|
||||
.map(|pair| format!("For want of a {} the {} was lost.", pair[0], pair[1]))
|
||||
.chain(std::iter::once(format!(
|
||||
"And all for the want of a {}.",
|
||||
list[0]
|
||||
)))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue