function isRowSorted(matrix, row) {
const cols = matrix[0].length;
for (let i = 0; i < cols; i++) {
if (matrix[row][i - 1] > matrix[row][i]) {
return false;
}
}
return true;
}
const matrix = [[ 4, 7, 9, 12],
[ 1, 8, 3, 4],
[-9, -4, -3, 2],
[-8, -3, -9, 4],
[ 2, 6, 7, 18]];
const rows = matrix.length;
let count = 0;
for (let i = 0; i < rows; i++) {
if (isRowSorted(matrix, i)) {
count++;
}
}
console.log("Total sorted rows: " + count);
/*
run:
Total sorted rows: 3
*/