2

Using flow chart lib I’m plotting a graph. Below is the x and y coordinates of the graph as an array.

var plottingPoints  = [[0, 3], [4, 8], [8, 5], [9, 23], [10, 2]];

I just need to pick largest value of the y coordinate (ie 23). Please need support of expertise.

3 Answers 3

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);
Sign up to request clarification or add additional context in comments.

Comments

2

In new browsers you can make use of ES5's .map method of arrays. Also, Math.max returns the highest value of all arguments:

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

Comments

1
var t=plottingPoints[0];
$(plottingPoints  ).each (function (i,n){

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

});

now , t[1] - is your answer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.