I have a two-dimensional array:
function getMatrix(size) {
var matrix = [];
for (var i = 0; i < size; i++) {
matrix[i] = new Array(size);
}
return matrix;
};
It is filled with numeric values, so every existing matrix[i][j] is a Number. What is the best way to get a sequence of i and j pairs that will correspond to a seqence of highest to lowest values in the matrix?
I’d create a class that has attributes
i,jandvalue. Create an object for each value in the matrix by filling i, j and the matrix value into this object. Put all objects in a list and sort the list withlist.sort(sortFunction)and a self-definedsortFunctionthat sorts the list byobject.value.Then print the
(i,j)pairs in the sorted list.