In Rust, although there is almost certainly a more efficient way of doing this.
fn main() { let wave = wave("hello"); for (_i, a) in wave.into_iter().enumerate() { println!("{}", a) } } fn wave(input: &str) -> Vec<String> { let mut result = Vec::new(); for (i, _c) in input.chars().enumerate() { let mut subresult = Vec::new(); for (ind, cha) in input.chars().enumerate() { if i == ind { subresult.push(cha.to_uppercase().to_string()); } else { subresult.push(cha.to_lowercase().to_string()); } } result.push(subresult.into_iter().collect::<String>()); } return result }
Playground link here.
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
Nice!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In Rust, although there is almost certainly a more efficient way of doing this.
Playground link here.
You can use concatenation to avoid a character by character copy.
I don't know the first thing about Rust, so this is probably not optimal either.
Playgrund link here
Nice!