Ruby Koan 151 raising exceptions

后端 未结 30 1634
孤独总比滥情好
孤独总比滥情好 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:16

    def triangle(a, b, c)
      [a, b, c].permutation do |sides|
        raise TriangleError unless sides[0] + sides[1] > sides[2]
      end
      case [a,b,c].uniq.size
        when 3; :scalene
        when 2; :isosceles
        when 1; :equilateral
      end
    end
    

提交回复
热议问题