in Coffeescript, Development

Getting min/max Values from multidimensional array in coffee script

Today I had to implement an algorithm to find the minimum and maximum values for a multidimensional array. The domain variable holds an array containing [min, max].

Behold the functional goodness of java-/coffeescript:

data =
  [
    {
      name: 'series 1'
      values: [5, 6, 7, 8]
    }
    {
      name: 'series 2'
      values: [1, 6, 7]
    }
  ]
domain =
  data
    .map (series) ->
      [
        Math.min.apply @, series.values
        Math.max.apply @, series.values
      ]
    .reduce (array, current) ->
      array[0] = Math.min array[0], current[0]
      array[1] = Math.max array[1], current[1]
      array
    , [Infinity, -Infinity]