Sha256: 34ff93691d91d27110c35c2b330bf171fc5378efdcba0c954b8bdac369550eb9

Contents?: true

Size: 617 Bytes

Versions: 102

Compression:

Stored size: 617 Bytes

Contents

pub fn reply(message: &str) -> &str {
    if is_silence(message) { "Fine. Be that way!" }
    else if is_yelling(message) && is_question(message) { "Calm down, I know what I'm doing!" }
    else if is_yelling(message) { "Whoa, chill out!" }
    else if is_question(message) { "Sure." }
    else { "Whatever." }
}

fn is_silence(message: &str) -> bool {
    message.trim().is_empty()
}

fn is_yelling(message: &str) -> bool {
    let s = message.trim_matches(|c: char| !c.is_alphabetic());
    !s.is_empty() && s.to_uppercase() == s
}

fn is_question(message: &str) -> bool {
    message.trim_right().ends_with("?")
}

Version data entries

102 entries across 102 versions & 1 rubygems

Version Path
trackler-2.2.1.97 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.96 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.95 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.94 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.93 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.92 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.91 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.90 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.89 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.88 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.87 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.86 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.85 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.84 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.83 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.82 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.81 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.80 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.79 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.78 tracks/rust/exercises/bob/example.rs