DEV Community

Discussion on: Check if the chain has the same amount

Collapse
 
kip13 profile image
kip

A simple solution with Rust.

fn main() {
    println!(
        "{} the same amount",
        if has_same_amount("$XxkkLLOoox-", "x", "o") {
            "Has"
        } else {
            "Not has"
        }
    )
}

fn has_same_amount(str: &str, ch1: &str, ch2: &str) -> bool {
    let str = str.to_lowercase();

    str.matches(ch1).count() == str.matches(ch2).count()
}
Has the same amount