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.179 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.178 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.177 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.176 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.175 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.174 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.173 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.172 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.171 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.170 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.169 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.167 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.166 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.165 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.164 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.163 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.162 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.161 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.160 tracks/rust/exercises/bob/example.rs
trackler-2.2.1.159 tracks/rust/exercises/bob/example.rs