Skip to content

Commit eaed6c0

Browse files
committed
Refactor loop variables
1 parent 043151f commit eaed6c0

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

JavaScript/1-for.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ console.log('Example 2');
1818
console.log('Example 3');
1919

2020
{
21-
let i = 0;
22-
for (; i < 3;) {
21+
for (let i = 0; i < 3;) {
2322
console.log(i++);
2423
}
2524
}

JavaScript/b-matrix.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ const res = matrix
1515

1616
console.log(res);
1717

18-
let i, j, row, col;
19-
for (i in matrix) {
20-
row = matrix[i];
21-
for (j in row) {
22-
col = row[j];
18+
for (const i in matrix) {
19+
const row = matrix[i];
20+
for (const j in row) {
21+
const col = row[j];
2322
console.log(i, j, col);
2423
}
2524
}

JavaScript/d-matrix-for-in.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ const matrix = [
77
[-6, 4, 8, 2, 0],
88
];
99

10-
let i, j, row, col;
11-
for (i in matrix) {
12-
row = matrix[i];
13-
for (j in row) {
14-
col = row[j];
10+
for (const i in matrix) {
11+
const row = matrix[i];
12+
for (const j in row) {
13+
const col = row[j];
1514
console.log(i, j, col);
1615
}
1716
}

0 commit comments

Comments
 (0)