exercism / elixir-analyzer

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

Exercism - High School Sweethearts Feedback #314

Closed krisrjohnson21 closed 2 years ago

krisrjohnson21 commented 2 years ago

Hello! Thanks for all you do within the coding community.

I recently completed the High School Sweethearts exercise for Elixir within Exercism. I got the following feedback from the Elixir Analyzer:

Reusing an already written function can help when writing maintainable code. Reuse existing functions:

initial/1 can reuse first_letter/1 initials/1 can reuse initial/1 pair/2 can reuse initials/1

However, my code does reuse these functions. It just doesn't seem to be picked up since they're interpolated into a string. This may be something worth improving, if possible! My code below:

defmodule HighSchoolSweetheart do
  def first_letter(name) do
    String.trim(name) |> String.first()
  end

  def initial(name) do
    "#{String.upcase(first_letter(name))}."
  end

  def initials(full_name) do
    initials = String.split(full_name)
    "#{initial(List.first(initials))} #{initial(List.last(initials))}"
  end

  def pair(full_name1, full_name2) do
    first_initials = String.split(full_name1)
    second_initials = String.split(full_name2)

                   """
                    ******       ******
                  **      **   **      **
                **         ** **         **
               **            *            **
               **                         **
               **     #{initial(List.first(first_initials))} #{initial(List.last(first_initials))}  +  #{initial(List.first(second_initials))} #{initial(List.last(second_initials))}     **
                **                       **
                  **                   **
                    **               **
                      **           **
                        **       **
                          **   **
                            ***
                             *
               """
  end
end
angelikatyborska commented 2 years ago

Hi! Your pair function doesn't call initials (it calls initial), that's why you're getting this comment.

krisrjohnson21 commented 2 years ago

Ah that makes sense, thank you @angelikatyborska! Happy to close this.