1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-19 14:16:55 +02:00
CodeWars/6kyu/camelcase_method/solution.rs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

19 lines
532 B
Rust

fn camel_case(str: &str) -> String {
let mut result = String::from("");
let mut was_space: bool = true;
for character in str.chars() {
if character.is_whitespace() {
was_space = true;
} else if character.is_alphabetic() {
if was_space {
result += &character.to_uppercase().to_string();
was_space = false;
} else {
result += &character.to_lowercase().to_string();
}
}
}
result.to_string()
}