Skip to content

Commit f9251e8

Browse files
committed
Add Refactor
1 parent 9a56d90 commit f9251e8

4 files changed

+19
-12
lines changed

JavaScriptFlippingAnImage.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ To invert an image means that each `0` is replaced by `1`, and each `1` is repla
2121
```JavaScript
2222
Input: image = [[1,1,0],[1,0,1],[0,0,0]]
2323
Output: [[1,0,0],[0,1,0],[1,1,1]]
24-
Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]]
25-
Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]]
24+
Explanation: First reverse each row:
25+
[[0,1,1],[1,0,1],[0,0,0]]
26+
Then, invert the image:
27+
[[1,0,0],[0,1,0],[1,1,1]]
2628
```
2729

2830
### 2<sup>nd</sup> Example
2931

3032
```JavaScript
3133
Input: image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
3234
Output: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
33-
Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]]
34-
Then, invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
35+
Explanation: First reverse each row:
36+
[[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]]
37+
Then, invert the image:
38+
[[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
3539
```
3640

3741
<br/>
@@ -49,9 +53,9 @@ Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]]
4953

5054
```JavaScript
5155
const flipAndInvertImage = (image) => {
52-
for(let row in image) {
56+
for (let row in image) {
5357
image[row] = image[row].reverse();
54-
image[row] = image[row].map(x=>1-x);
58+
image[row] = image[row].map(x => 1 - x);
5559
}
5660

5761
return image;

JavaScriptNumberOfIslands.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ const numIslands = (grid) => {
6262
};
6363

6464
const dfs = (grid, row, col) => {
65-
if (row < 0 || row >= grid.length || col < 0 || col >= grid[0].length) {
65+
if (row < 0 ||
66+
row >= grid.length ||
67+
col < 0 ||
68+
col >= grid[0].length) {
6669
return;
6770
}
6871

JavaScriptTransposeMatrix.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ Output: [[1,4],[2,5],[3,6]]
4040
const transpose = (A) => {
4141
let result = [];
4242

43-
for (let i= 0; i<A[0].length; i++) {
43+
for (let i = 0; i < A[0].length; i++) {
4444
let currentColumn = [];
4545

46-
for (let j=0; j<A.length; j++) {
46+
for (let j = 0; j < A.length; j++) {
4747
currentColumn.push(A[j][i]);
4848
}
4949

JavaScriptTwoSum.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Output: [0,1]
4949
const twoSum = (nums, target) => {
5050
let numsObject = {};
5151

52-
for(let i = 0; i < nums.length; i++) {
52+
for (let i = 0; i < nums.length; i++) {
5353
let n = nums[i],
5454
compliment = target-n;
5555

@@ -60,7 +60,7 @@ const twoSum = (nums, target) => {
6060
numsObject[n] = i;
6161
}
6262

63-
return [-1,-1];
63+
return [-1, -1];
6464
};
6565
```
6666

@@ -80,7 +80,7 @@ A `for` loop is used to iterate through each element in the `nums` array. Within
8080
An `if` statement checks if the `numsObject` object has a property with the value of `compliment`. If such a property exists, it means that a pair of numbers that add up to the target has been found.
8181
<br/>
8282

83-
In this case, the function returns an array containing the current index ( `i` ) and the index of the compliment in the `numsObject` object.
83+
In this case, the function returns an array containing the current index (`i`) and the index of the compliment in the `numsObject` object.
8484
<br/>
8585

8686
If the compliment property does not exist, it means that the current number has not been encountered before. In that case, the current number (`n`) is added as a property to the `numsObject` object, with the value of the current index (`i`).

0 commit comments

Comments
 (0)