Skip to content

Instantly share code, notes, and snippets.

@syphh
Created March 5, 2020 21:34
Show Gist options
  • Select an option

  • Save syphh/4a8202f1a06b213ed2ecbd9fb454edea to your computer and use it in GitHub Desktop.

Select an option

Save syphh/4a8202f1a06b213ed2ecbd9fb454edea to your computer and use it in GitHub Desktop.
function isLowerTriangular(mat){
let matSize = mat.length;
for(let i = 0; i < matSize; i++){
for(let j = i+1; j < matSize; j++){
if(mat[i][j] != 0)
return false;
}
}
return true;
}
let mat1 = [[2, 0, 0, 0],
[9, 5, 0, 0],
[8, 2, 4, 0],
[9, 4, 8, 3]];
let mat2 = [[1, 8, 3, 2],
[0, 5, 7, 6],
[7, 8, 4, 9],
[8, 6, 3, 3]];
console.log(isLowerTriangular(mat1));
console.log(isLowerTriangular(mat2));
/*Output:
true
false
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment