2011-10-25 25 views

回答

2
var plottingPoints = [[0, 3], [4, 8], [8, 5], [9, 23], [10, 2]]; 
var length = plottingPoints.length; 
var maxY = -Infinity; 
for(var i = 0; i < length; i++) 
    maxY = Math.max(plottingPoints[i][1], maxY); 
1
var t=plottingPoints[0]; 
$(plottingPoints ).each (function (i,n){ 

if (n[1]>t[1]) t=n; 

}); 

現在,T [1] - 是你的答案

2

在新的瀏覽器,您可以利用ES5的數組.map方法。此外,Math.max返回的所有參數的最高值:

// calculate max value of an array of numbers 
Math.max.apply(null, plottingPoints.map(function(element) { 
              // return y coordinate 
              return element[1]; 
             })); 
相關問題