DEV Community

Discussion on: ALGORITHM CHALLENGE: 1

Collapse
 
thebinarymutant profile image
Smit Patel • Edited

Was bored, so here's my rust code

use std::iter;

fn accum(input: &str) -> String {
    let len = input.len();
    input
        .chars()
        .enumerate()
        .flat_map(|(cnt, x)| {
            let cap = x.to_ascii_uppercase();
            let small = x.to_ascii_lowercase();
            iter::once(cap)
                .chain(iter::once(small).cycle().take(cnt))
                .chain(iter::once('-').filter(move |_| len - 1 != cnt))
        }).collect()
}