Created
October 25, 2020 11:45
-
-
Save mykhailokrainik/3952eaa12f6c119acc4c6c960b3f4a2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(assoc_char_funcs)] | |
use std::collections::VecDeque; | |
use std::iter::FromIterator; | |
fn main() -> Result<(), failure::Error> { | |
let a = "Hello World"; | |
dbg!(a | |
.split(" ") | |
.fold(String::with_capacity(a.len()), |mut acc, w| { | |
let mut s: VecDeque<char> = w.chars().collect(); | |
if s.len() > 2 { | |
s.swap(1, s.len() - 1); | |
} | |
if let Some(c) = s.pop_front() { | |
let v: Vec<char> = format!("{}", c as u32).chars().collect(); | |
v.into_iter().rev().for_each(|ch| s.push_front(ch)); | |
} | |
acc.push_str(&String::from_iter(s)); | |
acc.push(' '); | |
acc | |
}).trim_end()); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment