jsonify

jsonify

Exercism: Bob

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

Most Liked Responses

dogweather

dogweather

I believe that the top-level function (the cond) should be a restatement of the problem specification. It should be written using terms in the problem domain (teenagers) not the solution domain (whitespace, upper case, etc.). E.g.:

  def hey(input) do
    cond do
      question?(input) -> "Sure."
      yell?(input)     -> "Whoa, chill out!"
      nothing?(input)  -> "Fine. Be that way!"

      true -> "Whatever."
    end
  end

See how that code pretty much reads like the assignment for the problem. This is a big advantage of functional programming.

The implementation of these should then be done at gradually lower levels of abstraction. Here’s my solution: http://exercism.io/submissions/e7f0b1696ed14eaa99bc72bf882f2459

jsonify

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.

Qqwy

Qqwy

TypeCheck Core Team

Actually, it is possible to fix this Exercise without using regular expressions.

Here is my submission.

That’s right. all_letters_uppercase?/1 checks if upcasing would not change the string, while downcasing would.

  • First statement: True if string doesn’t contain any lowercase characters.
  • Second statement: True if string contains any uppercase characters.

The logical AND of these statements will return false if either there is a lowercase character, or there are no uppercase-characters at all.

Where Next?

Popular in Discussions Top

PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
WolfDan
After doing a port from a c++ library to my project in phoenix I’ve seen that I need a faster way to run this algorithm and I found this ...
New
mmmrrr
Just saw that dhh announced https://hotwire.dev/ Is it just me or is this essentially live view? :smiley: Although I like the “iFrame-e...
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New
acrolink
How does the two languages compare when it comes to server side application development? Any experiences or ideas? Thank you.
New
AstonJ
Can you believe the first professionally published Elixir book was published just 8 years ago? Since then I think we’ve seen more books f...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement