Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created March 26, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/6ddb1983cada163717f979f3fa9506ab to your computer and use it in GitHub Desktop.
Save rust-play/6ddb1983cada163717f979f3fa9506ab to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
println!("{:?}", series("92017", 0));
}
fn series(digits: &str, len: usize) -> Vec<String> {
let mut result: Vec<String> = Vec::new();
if len <= digits.len() && len != 0 {
result = digits
.as_bytes()
.windows(len)
.map(|sl| String::from_utf8(sl.to_vec()).unwrap())
.collect::<Vec<String>>();
} else if len == 0 {
result = vec!["".to_string(); digits.len()+1];
}
result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment