Having problems. X(
I can seem to only get the answer for either one of the problem sets or the other with this code but not both. I assume the problem is with my height/width constants but I think I've been staring at the problem too long.
Going to take the dog for a walk and come back to it.
Need to do this without the help of built in functions.
I already have MaxNumInColumns function completed.
So I just need to compare that array and find the similar number within the array from the function MinNumInRows(below) and then I get my correct answer for the Lucky Number Function.
What I have tried:
function minNumsInRows(matrix) {
const height = matrix.length;
const width = matrix.length;
const minColumns = [];
for (let row = 0; row < width; row++) {
let rowMin = matrix[row][0];
for ( let col = 0; col < height+1; col++) {
if (rowMin < matrix[row][col]) {
console.log(rowMin, "Compared to: ", matrix[row][col])
console.log("Row Num: ", row)
rowMin = rowMin;
} else {
rowMin = matrix[row][col]
}
} minColumns.push(rowMin)
}
console.log("End")
return minColumns;
};
matrix = [[ 5, 9, 21],
[ 9, 19, 6],
[12, 14, 15]]
console.log(minNumsInRows(matrix));
matrix = [[ 5, 10, 8, 6],
[10, 2, 7, 9],
[21, 15, 19, 10]]
console.log(minNumsInRows(matrix));
it works for the first but not the second. First is 3 x 3 so I understand why it works.
However, if I change the width const to:
const width = matrix[0].length;
I get an undefined error where I assumed it would give me a value of 4. :(
I can tweak the function to work for ONE or the OTHER, but not both.
Time to take the pup for a walk and hit the procelain throne. :)
Much appreciated for the help AND explaination(I don't want JUST an answer, please.) <3