How do I access the array sum here?

后端 未结 2 1372
-上瘾入骨i
-上瘾入骨i 2021-01-21 00:37

I have a data set that looks roughly like this:

var dataset = [
  // apples
  [{\"x\": 1, \"y\": 5 }, { \"x\": 2, \"y\": 4 }, { \"x\": 3, \"y\": 2 }, { \"x\": 4,         


        
2条回答
  •  青春惊慌失措
    2021-01-21 00:55

    d3.zip() comes in handy here, since you're manipulating data based on array index.

    https://jsfiddle.net/guanzo/o8voyydx/2/

    var result = dataset.map(d=>d.map(d=>d.y))
    result = d3.zip.apply(undefined,result)
    result = d3.max(result.map(d=>d3.sum(d)))
    console.log(result )//83
    

提交回复
热议问题