Sha256: b9ed744a51b52f931cde4f547eb0add3f6729f786f29d60c9f65e079f5c75ff7
Contents?: true
Size: 725 Bytes
Versions: 396
Compression:
Stored size: 725 Bytes
Contents
Array::uniq = -> output = {} output[@[key]] = @[key] for key in [0...@length] value for key, value of output class Triangle constructor: (side1, side2, side3) -> @sides = [side1, side2, side3] checkNegative @sides checkInequality @sides kind: -> if @sides.uniq().length == 1 'equilateral' else if @sides.uniq().length == 2 'isosceles' else 'scalene' checkNegative = (sides) -> for side in sides throw 'negative sides are illegal' if side < 0 checkInequality = (sides) -> if sides[0] + sides[1] <= sides[2] || sides[1] + sides[2] <= sides[0] || sides[0] + sides[2] <= sides[1] throw 'violation of triangle inequality' module.exports = Triangle
Version data entries
396 entries across 396 versions & 1 rubygems