Ruby Koan 151 raising exceptions

后端 未结 30 2112
孤独总比滥情好
孤独总比滥情好 2021-01-31 14:34

I\'m going through the ruby koans, I\'m on 151 and I just hit a brick wall.

Here is the koan:

# You need to write the triangle method in the file \'trian         


        
30条回答
  •  渐次进展
    2021-01-31 15:08

    You forgot the case when a,b, or c are negative:

    def triangle(a, b, c)
      raise TriangleError if [a,b,c].min <= 0
      x, y, z = [a,b,c].sort
      raise TriangleError if x + y <= z
      [:equilateral,:isosceles,:scalene].fetch([a,b,c].uniq.size - 1)
    end
    

提交回复
热议问题