Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb86b30

Browse files
committed
Code style fixes for matrix rotation algorithm.
1 parent57378c5 commitbb86b30

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

‎src/algorithms/uncategorized/square-matrix-rotation/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ A B C
9292
/ / •
9393
/ • •
9494
95-
Andnot let's do horizontal reflection:
95+
Andnow let's do horizontal reflection:
9696
9797
A → →
9898
B → →
9999
C → →
100100
101-
The string has been rotated to 90 degree.
101+
The string has been rotated to 90 degree:
102102
103103
• • A
104104
• • B

‎src/algorithms/uncategorized/square-matrix-rotation/squareMatrixRotation.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,28 @@ export default function squareMatrixRotation(originalMatrix) {
88
// Do top-right/bottom-left diagonal reflection of the matrix.
99
for(letrowIndex=0;rowIndex<matrix.length;rowIndex+=1){
1010
for(letcolumnIndex=rowIndex+1;columnIndex<matrix.length;columnIndex+=1){
11-
consttmp=matrix[columnIndex][rowIndex];
12-
matrix[columnIndex][rowIndex]=matrix[rowIndex][columnIndex];
13-
matrix[rowIndex][columnIndex]=tmp;
11+
// Swap elements.
12+
[
13+
matrix[columnIndex][rowIndex],
14+
matrix[rowIndex][columnIndex],
15+
]=[
16+
matrix[rowIndex][columnIndex],
17+
matrix[columnIndex][rowIndex],
18+
];
1419
}
1520
}
1621

1722
// Do horizontal reflection of the matrix.
1823
for(letrowIndex=0;rowIndex<matrix.length;rowIndex+=1){
1924
for(letcolumnIndex=0;columnIndex<matrix.length/2;columnIndex+=1){
20-
constmirrorColumnIndex=matrix.length-columnIndex-1;
21-
consttmp=matrix[rowIndex][mirrorColumnIndex];
22-
matrix[rowIndex][mirrorColumnIndex]=matrix[rowIndex][columnIndex];
23-
matrix[rowIndex][columnIndex]=tmp;
25+
// Swap elements.
26+
[
27+
matrix[rowIndex][matrix.length-columnIndex-1],
28+
matrix[rowIndex][columnIndex],
29+
]=[
30+
matrix[rowIndex][columnIndex],
31+
matrix[rowIndex][matrix.length-columnIndex-1],
32+
];
2433
}
2534
}
2635

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp