Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

二维数据聚合求最大值,用JavaScript或者Java怎么实现啊?

d91cfd87ef7399f82ac2349ff3d9865.png
有主臂工作半径和主臂实际载荷这两个字段
8634619ed662e1aef01b7c0fffdb8bb.png
这个图是我统计生成的,横轴是主臂工作半径值区间,纵轴是这个区间的值出现的次数。比如半径大于18小于19的值出现了3142次,这3142个半径值在上面excel表里就对应3142个主臂实际载荷的值,现在我想取这3142个主臂实际载荷值中的最大值。也就是说,最终的需求就是,取每个半径值区间内最大的主臂实际载荷值。用JavaScript或者Java怎么写啊?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

生成图表可以用 echarts 之类的

单纯计算的话就是遍历呗,看上去你把 key 向下取整,然后 value 取最大值,赋值保存即可

image.png

[
    [1.1,2],
    [1.1,3],
    [1.1,4],
    [1.1,5],
    [1.1,4],
    [1.9,1],
    [1.3,2],
    [1.3,3],
    [1.3,4],
    [1.3,5],
    [1.3,4],
    [1.3,1],
    [1.3,2],
    [1.3,3],
    [3.3,4],
    [1.3,5],
    [5.3,4],
    [1.3,1],
    [9.9,1]
].reduce((s, v)=>{
    key = v[0]>>0;
    s[key] = Math.max(s[key] || 0, v[1])
    return s
},{})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...