DEV Community

Discussion on: Daily Challenge #15 - Stop gninnipS My sdroW!

qm3ster profile image
Mihail Malo • Edited on

Rust, sort of in place

fn reverse_in_place(input: &mut [u8]) {
        .split_mut(|&byte| byte == b' ')
        .filter(|word| word.len() >= 5)

The rest of the story below the fold:

fn reverse(input: &str) -> String {
    let mut output = input.as_bytes().to_vec();
    reverse_in_place(&mut output);

fn main() {
    let test = "Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!";
    println!("{}", reverse(test));
    println!("{}", reverse(&reverse(test)));