How to compare columns two-dimensional array(matrix)?

5a352e3ba0f87917558966.png
June 10th 19 at 14:24
1 answer
June 10th 19 at 14:26
for (var i = 0; i < arr[0].length; ++i) {
 if (arr[i][0] != arr[i][1]) {
 // not equal
}
}
But if I add another row? - dakota.Sipes commented on June 10th 19 at 14:29
,
var len = arr[0].length;
for (var i = 0; i < len; ++i) {
 var eq = true;

 for (var j = 0; j < arr[i].length - 1; ++j) {
 if (arr[i][j] != arr[i][j + 1]) {
 eq = false;
break;
}
}

 if (!eq) {
 console('column' + (i + 1) + 'values are not equal');
}
}
- Adriel51 commented on June 10th 19 at 14:32

Find more questions by tags FrontendAlgorithmsJavaScript