exercism/elixir/bob/lib/bob.ex

24 lines
558 B
Elixir
Raw Normal View History

2024-03-10 12:14:17 +00:00
defmodule Bob do
@spec hey(String.t()) :: String.t()
def hey(input) do
trimmed = String.trim(input)
is_yell? = String.upcase(trimmed) == trimmed and String.downcase(trimmed) != trimmed
is_question? = String.ends_with?(trimmed, "?")
is_silence? = trimmed == ""
cond do
is_silence? ->
"Fine. Be that way!"
is_yell? and is_question? ->
"Calm down, I know what I'm doing!"
is_question? ->
"Sure."
is_yell? ->
"Whoa, chill out!"
true ->
"Whatever."
end
end
end