Skip to content

Latest commit

 

History

History
39 lines (34 loc) · 1.13 KB

uefa_euro_2016.md

File metadata and controls

39 lines (34 loc) · 1.13 KB

Description

Finish the uefaEuro2016() function so it return string just like in the examples below:

uefa_euro_2016(['Germany', 'Ukraine'],[2, 0]) # "At match Germany - Ukraine, Germany won!"
uefa_euro_2016(['Belgium', 'Italy'],[0, 2]) # "At match Belgium - Italy, Italy won!"
uefa_euro_2016(['Portugal', 'Iceland'],[1, 1]) # "At match Portugal - Iceland, teams played draw."

My Solution

def uefa_euro_2016(teams, scores)
  if scores.first > scores.last
    "At match #{teams.first} - #{teams.last}, #{teams.first} won!"
  elsif scores.first < scores.last
    "At match #{teams.first} - #{teams.last}, #{teams.last} won!"
  else
    "At match #{teams.first} - #{teams.last}, teams played draw."
  end
end

Better/Alternative solution from Codewars

def uefa_euro_2016(teams, scores)
  outcome = case scores.inject(:<=>)
            when 0
              "teams played draw."
            when 1
              "#{teams.first} won!"
            else
              "#{teams.last} won!"
            end

  "At match #{teams.join(' - ')}, #{outcome}"
end