jsonify
I’m trying to continue to wrap my brain around how I should be structuring things and I’m getting stuck on the Bob exercise of Exercism. Here is my code and right now, I’m just not understanding why my “Talking in capitals” test isn’t passing like I think it should:
defmodule Bob do
def hey(" "), do: "Fine. Be that way!"
def hey(""), do: "Fine. Be that way!"
def hey(message) do
cond do
shouting?(message) -> "Whoa, chill out!"
asking?(message) -> "Sure."
shout_numbers?(message) -> "Whoa, chill out!"
capitals_letters?(message) -> "Whatever"
# true -> "Whatever."
end
end
defp shouting?(message) do
message == String.upcase(message)
end
defp asking?(message) do
String.ends_with?(message, "?")
end
defp shout_numbers?(message) do
message
|> String.upcase()
String.ends_with?(message, "?")
end
defp capitals_letters?(message) do
message
|> String.split(" ")
|> String.capitalize
Enum.join(" ")
end
end
Trending in Discussions
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
Your solution isn’t quite generalized.
You shouldn’t have anything aside of the
cond, as well as there shouldn’t be more than 4 clauses in it, Chill out, be that way, Sure, and Whatever.There is no reason to have any of the strings to be returned at more than one place.
Also your current version of shouting does consider
"1, 2, 3"shout…The cases you need to recognize is if the input was shout (at least one alphabetic character and all alphabetics are in uppercase), if it was a question, if it was silence or if it was none of the former.
themarlzy
Your
capital_letters?function returns a string, whereas I believe you’re after a true/false?Here was my solution which passes the tests, should you want to have a peak.
http://exercism.io/submissions/8314666634e546708d242d5f6d9a06d4
jsonify
While this is still a work in progress, my goal was to get all of the tests to pass first, then refactor while learning more about how to better use Elixir. Thank you for the feedback.
jsonify
How would you have known to use
[\p{L}]in your Regex.match?/2 function? I would NEVER have even begun to figure that one out. Great solution, though.themarlzy
I know a little regex, though, Dr. Google was helpful in this instance.
jsonify
So if I may ask, what exactly did you Google as your search? Did you know that you needed to search for the Unicode solution? Just trying to get a better feel for how one would go about how to figure out how to come to a solution. When I saw your solution, all the pieces made sense and I thought, "of course that makes sense how that was solved. " But it’s the how that conclusion was reached that truly interests me. What steps did you go through to get the results you were looking for.
themarlzy
@jsonify, I will try to break out the process some more
Punctuation regex, yielded this article http://www.regular-expressions.info/posixbrackets.html
That was working well, except it was leaving in $ and ^, so added those on top.
Then it was failing the last test with the diaeresis on the o (ö). It was stripping it off and turning it into a binary e.g.
<<107>>or whatever. Then, after about an hour of trying stuff, I tried the option for unicodeuat the end of the~r/regex/u.Hope that was helpful.
M
Qqwy
Actually, it is possible to fix this Exercise without using regular expressions.
Here is my submission.
That’s right.
all_letters_uppercase?/1checks if upcasing would not change the string, while downcasing would.The logical AND of these statements will return false if either there is a lowercase character, or there are no uppercase-characters at all.
NobbZ
Please link to your submission at exercism, then we could like it or comment.
Qqwy
Of course, how did I forget.
Here is the submission on Exercism.