2014-10-02 90 views
0

我正在寻找在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倍。

该系列是从这个红宝石功能传递。 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 
+0

你能举例说明数据吗?看起来变量并不总是指同一事物。 – 2014-10-02 18:15:13

+0

如果我们知道'series'看起来像什么和结果应该是什么,可能会有所帮助。 – 2014-10-02 18:15:27

+0

我添加了一些信息。示例数据将是一个包含X和Y值的系列(其中X只是一个增量,而Y是从0到15000的编号值)。这有帮助吗? – SwimJim 2014-10-02 19:00:39

回答

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