Ruby Koan 151 raising exceptions

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

    After try to understand what I must to do with koan 151, I got it with the first posts, and get lot fun to check everyone solution :) ... here is the mine:

    def triangle(a, b, c)
      array = [a, b, c].sort
      raise TriangleError if array.min <= 0 || array[0]+array[1] <= array[2]
      array.uniq!
      array.length == 1 ? :equilateral: array.length == 2 ? :isosceles : :scalene
    end
    

    Koan is a very interesting way to learn Ruby

提交回复
热议问题