exercism / elixir-analyzer

GNU Affero General Public License v3.0
30 stars 32 forks source link

Analysis of High_Score #302

Closed randre03 closed 2 years ago

randre03 commented 2 years ago

I received the following feedback to my answer to the High Score problem:

Use Map.update instead of Map.put + Map.get in update_score to update scores in a single call. For the updating function, define an anonymous function using fn or the & operator shorthand.

However, my code uses elixir's syntax sugar for updating the map as see here

  def update_score(scores, name, score) do
    if Map.has_key?(scores, name) do
      %{scores | name => score + scores[name]}
    else
      add_player(scores, name, score)
    end
  end