Sha256: f144efba24ad4c17f336c828c568b5d42dac5ac6be979c8627de8ddbb1445c36

Contents?: true

Size: 781 Bytes

Versions: 7

Compression:

Stored size: 781 Bytes

Contents

use "itertools"

primitive Bob
  fun apply(phrase: String): String =>
    if _silent(phrase) then
      "Fine. Be that way!"
    elseif _loud(phrase) then
      "Whoa, chill out!"
    elseif _question(phrase) then
      "Sure."
    else
      "Whatever."
    end

  fun _silent(phrase: String): Bool =>
    phrase.clone().>strip() == ""

  fun _loud(phrase: String): Bool =>
    Iter[U8](phrase.values()).all(this~_not_lowercase())
      and Iter[U8](phrase.values()).any(this~_is_letter())

  fun _not_lowercase(b: U8): Bool =>
    (b < 'a') and ('z' > b)

  fun _is_letter(b: U8): Bool =>
    (('a' <= b) and (b <= 'z')) or (('A' <= b) and (b <= 'Z')) 

  fun _question(phrase: String): Bool =>
    try
      Iter[U8](phrase.values()).last()? == '?'
    else
      false
    end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
trackler-2.2.1.13 tracks/pony/exercises/bob/example.pony
trackler-2.2.1.12 tracks/pony/exercises/bob/example.pony
trackler-2.2.1.11 tracks/pony/exercises/bob/example.pony
trackler-2.2.1.10 tracks/pony/exercises/bob/example.pony
trackler-2.2.1.9 tracks/pony/exercises/bob/example.pony
trackler-2.2.1.8 tracks/pony/exercises/bob/example.pony
trackler-2.2.1.7 tracks/pony/exercises/bob/example.pony