Created
January 2, 2018 01:28
-
-
Save earlonrails/ef049c77027a0ec6d0d9fe266254919f to your computer and use it in GitHub Desktop.
Revisions
-
earlonrails created this gist
Jan 2, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ #!/usr/bin/env node // https://www.geeksforgeeks.org/find-if-given-matrix-is-toeplitz-or-not/ class Toeplitz { static check(matrix) { for (var i = 1; i < matrix.length - 1; i++) { let row = matrix[i] let prevRow = matrix[i - 1] for (var j = 1; j < row.length - 1; j++) { let diagonalParent = prevRow[j - 1] if (diagonalParent != row[j]) { return false } } } return true } } var isToe = [ [6, 7, 8, 9], [4, 6, 7, 8], [1, 4, 6, 7], [0, 1, 4, 6], [2, 0, 1, 4] ] console.log("Should be a Toeplitz:", Toeplitz.check(isToe)) var isNotToe = [ [6, 7, 8, 9], [4, 6, 6, 8], [1, 2, 6, 7], [0, 1, 4, 6], [2, 8, 1, 4] ] console.log("Should be a Toeplitz:", Toeplitz.check(isNotToe))