-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d17202
commit 61fccfa
Showing
4 changed files
with
17 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
// Проверка квадратной ли матрица | ||
export function isSquareMatrix(matrix: number[][]): boolean { | ||
const rows = matrix.length; | ||
if (rows === 0) { | ||
return false; // Пустая матрица не считается квадратной | ||
return false; | ||
} | ||
|
||
for (const row of matrix) { | ||
if (row.length !== rows) { | ||
return false; // Если хотя бы одна строка не имеет той же длины, что и количество строк, то это не квадратная матрица | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// Виведення матриці | ||
export function roundedRow(row: number[]) { | ||
return row.map((value) => { | ||
const res = Math.round(value * 1000) / 1000; | ||
if (Object.is(res, -0)) return 0; | ||
else return res; | ||
}); | ||
} | ||
|
||
export function roundedMatrix(matrix: number[][]): number[][] { | ||
return matrix.map((value) => roundedRow(value)); | ||
} | ||
|
||
export function printMatrix(matrix: number[][]): void { | ||
for (const row of matrix) { | ||
console.log(roundedRow(row).join("\t")); | ||
} | ||
} | ||
|
||
export function roundedRow(row: number[]) { | ||
return row.map((value) => Math.round(value * 1000) / 1000); | ||
} |