DEV Community

Discussion on: Daily Challenge #44 - Mexican Wave

Collapse
 
serbuvlad profile image
Șerbu Vlad Gabriel • Edited

You can use concatenation to avoid a character by character copy.

...
    for (i, c) in input.chars().enumerate() {
        let upper = c.to_uppercase().to_string();
        let subresult = input[..i].to_string() + &upper + &input[i+upper.len()..];
        result.push(subresult);
    }
...

I don't know the first thing about Rust, so this is probably not optimal either.

Playgrund link here

Collapse
 
necrotechno profile image
NecroTechno

Nice!