Employee badge labels are formatted as follows: "[id] - name - DEPARTMENT".
Implement the NameBadge.print/3 function. It should take an id, name, and a department. It should return the badge label, with the department name in uppercase.
Due to a quirk in the computer system, new employees occasionally don't yet have an ID when they start working at the factory. As badges are required, they will receive a temporary badge without the ID prefix.
Extend the NameBadge.print/3 function. When the id is missing, it should print a badge without it.
Even the factory's owner has to wear a badge at all times. However, an owner does not have a department. In this case, the label should print "OWNER" instead of the department name.
Extend the NameBadge.print/3 function. When the department is missing, assume the badge belongs to the company owner.
Note that it is possible for the owner to also be a new employee.
https://exercism.org/tracks/elixir/exercises/name-badge
defmodule NameBadge do
@moduledoc """
if else condition and nil
"""
@owner "OWNER"
@middle_separator " - "
def print(id, name,department) do
id = if id, do: "[#{id}]"
department = if department, do: "#{String.upcase(department)}", else: @owner
[id, name, department]
|> Enum.reject(fn value -> value === nil end)
|> Enum.map_join(@middle_separator, &(&1))
end
# @doc """
# practice with if else condition
# """
# @spec print(integer() | nil, String.t(), String.t() | nil) :: String.t()
# def print(id, name, department) do
# id = if id, do: "[#{id}] - "
# department = if department, do: "#{String.upcase(department)}", else: "OWNER"
# "#{id}#{name} - #{department}"
# end
end