返回coffeescript中多个数组的最后一个最大值

时间:2014-10-02 14:13:22

标签: arrays coffeescript

我希望在coffeescript中找到传递给我的多个数组中的最后一个值。我有一些代码可以用于获得类似的结果,但是我无法将它们放在一起。 我在这里定义了一系列值。

  series = @_parseData {points: @get('points'), series: @get('series')}

这将获得一系列数组的最大值。

  maxvalue = Math.max(answer, (point?.y or 0)) for point in s.data for s in series

这将获得一个数组中的最后一个值。

 data = series[0].data
    answer = data[data.length - 1].y

这将得到多个数组中最后一个值的总和。

answer += s.data[s.data.length - 1].y or 0 for s in series

任何帮助将不胜感激。我的语法有问题。

不同系列中的值是针对Y轴传递的数字,一条线在人力车上。它们应该是200-15000之类的数字。每次图形获得更多数据时,X轴基本上只是一个增量30。

该系列从这个ruby函数传递。 totinarr和totoutarr只是用作增量计数器的数组。 totin和totout是作为数据值传递的浮点数。

def graphfunction( totin, totinarr, totout, totoutarr, grphname )
  if ( totinarr.last[:y] != totin) | ( totoutarr.last[:y] != totout )

    totinarr.shift
    totinarr.last[:x] += 30
    totinarr << { x: totinarr.last[:x], y: totin }

    totoutarr.last[:y] != totout
    totoutarr.shift
    totoutarr.last[:x] += 30
    totoutarr << {x: totoutarr.last[:x], y: totout }

  end
  totdata = [
    {
      name: "graph1",
      data: totinarr
    },
    {
      name: "graph2",
      data: totoutarr
    }
  ]
  send_event( grphname , series: totdata)
  return true
end

1 个答案:

答案 0 :(得分:0)

我能够找到解决方案。这里是。

  series = @_parseData {points: @get('points'), series: @get('series')}
  answer = 0
  answer = s.data[s.data.length - 1].y for s in series when s.data[s.data.length - 1].y > answer
  values = answer