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

Version Path
trackler-2.2.1.180 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.179 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.178 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.177 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.176 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.175 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.174 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.173 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.172 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.171 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.170 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.169 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.167 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.166 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.165 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.164 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.163 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.162 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.161 tracks/coffeescript/exercises/triangle/example.coffee
trackler-2.2.1.160 tracks/coffeescript/exercises/triangle/example.coffee