aboutsummaryrefslogtreecommitdiff
path: root/challenge-332/benjamin-andre/rust/ch-2.rs
blob: f847c4af3c44917b23ca210feb7e9b2ed0f232c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
//usr/bin/env rustc --test $0 -o kachow && ./kachow --nocapture; rm -f kachow ; exit

fn odd_letters(s: &str) -> bool {
    let mut counts = std::collections::HashMap::new();
    for c in s.chars() {
        *counts.entry(c).or_insert(0) += 1;
    }
    counts.values().all(|&count| count % 2 == 1)
}

#[test]
fn example() {
    assert_eq!(odd_letters("weekly"), false);
    assert_eq!(odd_letters("perl"), true);
    assert_eq!(odd_letters("challenge"), false);
}