mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-15 10:11:47 -06:00
bob elixir solution
This commit is contained in:
31
elixir/bob/lib/bob.ex
Normal file
31
elixir/bob/lib/bob.ex
Normal file
@@ -0,0 +1,31 @@
|
||||
defmodule Bob do
|
||||
def hey(input) do
|
||||
input = String.trim(input)
|
||||
|
||||
uppercase =
|
||||
Enum.all?(
|
||||
Enum.filter(String.graphemes(input), &String.match?(&1, ~r/^\p{L}$/u)),
|
||||
&String.match?(&1, ~r/^\p{Lu}$/u)
|
||||
)
|
||||
|
||||
has_letters = Enum.any?(String.graphemes(input), &String.match?(&1, ~r/^\p{L}$/u))
|
||||
question = String.ends_with?(input, "?")
|
||||
|
||||
cond do
|
||||
String.length(input) == 0 ->
|
||||
"Fine. Be that way!"
|
||||
|
||||
has_letters && uppercase && question ->
|
||||
"Calm down, I know what I'm doing!"
|
||||
|
||||
question ->
|
||||
"Sure."
|
||||
|
||||
has_letters && uppercase ->
|
||||
"Whoa, chill out!"
|
||||
|
||||
true ->
|
||||
"Whatever."
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user