samedi 16 mai 2020

Syntax error, unexpected tIDENTIFIER, expecting ')' Ruby

I get the following error when running a simple method that takes in a proper noun string and returns the string properly capitalized.

def format_name(str)
    parts = str.split
    arr = []
    parts.map do |part|
      if part[0].upcase
      else part[1..-1].downcase
      arr << part
      end
    end
 return arr.join(" ")
end

Test cases: puts format_name("chase WILSON") # => "Chase Wilson" puts format_name("brian CrAwFoRd scoTT") # => "Brian Crawford Scott"

Aucun commentaire:

Enregistrer un commentaire