DEV Community

loading...

Discussion on: Daily Challenge #259 - Duplicate Encoder

Collapse
lexlohr profile image
Alex Lohr

Rust πŸ¦€πŸ¦€πŸ¦€πŸ¦€solution:πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€ πŸ¦€

fn encode_duplicate_characters(text: &str) -> String {
    let text = text.to_lowercase();
    text.chars().map(|c| if text.matches(c).count() == 1 { '(' } else { ')' }).collect()
}