I managed to create a 2d array and populate it automatically with my code. I'd like to find the min value on the main diagonal, but I'm stuck and have no idea how to approach that idea from my code. Can anyone explain me how can I manage to achieve this pretty please? Everything that I've tried or come up with gave no results whatsoever..
var matrix = Array.from(Array(10), () => new Array(10));
for(i=0; i<10; i++){
for(j=0; j<10; j++)
matrix[i][j] = Math.floor(Math.random() * 100);
}
console.log(matrix);
Construct a 1-d array of the diagonal. Use Math.min with .apply to find the min value in that array.
var matrix = Array.from(Array(10), () => new Array(10));
for(i=0; i<10; i++){
for(j=0; j<10; j++)
matrix[i][j] = Math.floor(Math.random() * 100);
}
const diag = matrix.map((m, i) => m[i]);
const min = Math.min.apply(null, diag);
console.log(diag, "min = " + min);