Skip to content

Commit df2f337

Browse files
Added eslint
1 parent b64dd4c commit df2f337

27 files changed

+1653
-40
lines changed

.eslintrc.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
"env": {
3+
"node": true,
4+
"es2021": true
5+
},
6+
7+
"extends": "eslint:recommended",
8+
"parserOptions": {
9+
"ecmaVersion": "latest",
10+
"sourceType": "module"
11+
},
12+
"rules": {
13+
"indent": [
14+
"error",
15+
2
16+
],
17+
"linebreak-style": [
18+
"error",
19+
"unix"
20+
],
21+
"quotes": [
22+
"error",
23+
"double"
24+
],
25+
"semi": [
26+
"error",
27+
"always"
28+
]
29+
}
30+
};

LeetcodeProblems/Algorithms/Add_Two_Numbers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var addTwoNumbers = function (l1, l2) {
4141

4242
const head = number;
4343
while (l1 !== null || l2 !== null) {
44-
var elem = carry;
44+
elem = carry;
4545
if (l1 !== null) {
4646
elem += l1.val;
4747
l1 = l1.next;

LeetcodeProblems/Algorithms/Backspace_String_Compare.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ Can you solve it in O(N) time and O(1) space?
4040
var backspaceCompare = function (S, T) {
4141
var iterS = S.length - 1;
4242
var iterT = T.length - 1;
43-
43+
var countBack = 0;
44+
4445
while (iterS >= 0 || iterT >= 0) {
4546
if (iterS >= 0 && S.charAt(iterS) === "#") {
46-
var countBack = 0;
47+
countBack = 0;
4748
while (iterS >= 0 && (countBack > 0 || S[iterS] === "#")) {
4849
if (iterS >= 0 && S[iterS] === "#") {
4950
countBack++;
@@ -54,7 +55,7 @@ var backspaceCompare = function (S, T) {
5455
iterS--;
5556
}
5657
} else if (iterT >= 0 && T.charAt(iterT) === "#") {
57-
var countBack = 0;
58+
countBack = 0;
5859
while (iterT >= 0 && (countBack > 0 || T[iterT] === "#")) {
5960
if (iterT >= 0 && T[iterT] === "#") {
6061
countBack++;
@@ -85,7 +86,7 @@ var backspaceCompare2 = function (S, T) {
8586
}
8687

8788
var stackT = [];
88-
for (var i = 0; i < T.length; i++) {
89+
for (i = 0; i < T.length; i++) {
8990
if (T.charAt(i) === "#") stackT.shift();
9091
else stackT.unshift(T.charAt(i));
9192
}

LeetcodeProblems/Algorithms/Clone_Graph.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ You don't need to understand the serialization to solve the problem.
4040
* }
4141
*/
4242

43+
class UndirectedGraphNode {} //TODO: Define me
44+
4345
// SOLUTION 1 Using DFS
4446
/**
4547
* @param {UndirectedGraphNode} graph
@@ -93,3 +95,6 @@ var cloneGraphBFS = function (graph) {
9395

9496
return copyReturn;
9597
};
98+
99+
module.exports.cloneGraph = cloneGraph;
100+
module.exports.cloneGraphBFS = cloneGraphBFS;

LeetcodeProblems/Algorithms/Coin_Change.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var coinChange = function (coins, amount) {
2525
for (var i = 0; i <= amount; i++) memo[i] = Number.POSITIVE_INFINITY;
2626

2727
memo[0] = 0;
28-
for (var i = 0; i < coins.length; i++) {
28+
for (i = 0; i < coins.length; i++) {
2929
const coin = coins[i];
3030
for (var j = coin; j < memo.length; j++)
3131
memo[j] = min2(memo[j], memo[j - coin] + 1);
@@ -105,3 +105,5 @@ var min = function (a, b, c) {
105105
};
106106

107107
module.exports.coinChange = coinChange;
108+
module.exports.coinChange1 = coinChange1;
109+
module.exports.coinChange2 = coinChange2;

LeetcodeProblems/Algorithms/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var buildTree = function (preorder, inorder) {
4040
inorder === null ||
4141
preorder.length !== inorder.length
4242
)
43-
return nil;
43+
return null;
4444

4545
return buildTreeAux(
4646
preorder,

LeetcodeProblems/Algorithms/Edit_Distance.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ var minDistance = function (word1, word2) {
4141
}
4242
}
4343

44-
for (var i = 1; i <= word1.length; i++) {
45-
for (var j = 1; j <= word2.length; j++) {
44+
for (i = 1; i <= word1.length; i++) {
45+
for (j = 1; j <= word2.length; j++) {
4646
if (word1.charAt(i - 1) === word2.charAt(j - 1)) {
4747
matrix[i][j] = matrix[i - 1][j - 1];
4848
} else {
@@ -90,7 +90,7 @@ var minDistanceAux = function (word1, word2, iter1, iter2) {
9090
);
9191
};
9292

93-
var min = function (a, b, c) {
93+
min = function (a, b, c) {
9494
if (a < b) return a < c ? a : c;
9595

9696
return b < c ? b : c;

LeetcodeProblems/Algorithms/Escape_The_Ghosts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The number of ghosts will not exceed 100.
4444
*/
4545
var escapeGhosts = function (ghosts, target) {
4646
var distancePacman = getDistance([0, 0], target);
47-
for (ghost in ghosts) {
47+
for (var ghost in ghosts) {
4848
const distanceGhost = getDistance(ghosts[ghost], target);
4949
if (distancePacman > distanceGhost) return false;
5050
}

LeetcodeProblems/Algorithms/Generate_Parenthesis.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var generateParenthesisApproach1 = function (n) {
2020
if (n === 0) return [];
2121

2222
var str = "(".repeat(n);
23-
sol = [];
23+
var sol = [];
2424

2525
genParAux(str, 0, 0, sol);
2626
return sol;
@@ -93,4 +93,5 @@ var insertAt = function (str, position, value) {
9393
return str.slice(0, position) + value + str.slice(position);
9494
};
9595

96+
module.exports.generateParenthesisApproach1 = generateParenthesisApproach1;
9697
module.exports.generateParenthesisApproach2 = generateParenthesisApproach2;

LeetcodeProblems/Algorithms/Group_Anagrams.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var groupAnagrams = function (strs) {
3333
}
3434
}
3535

36-
for (key in hashMap) ret.push(hashMap[key]);
36+
for (var key in hashMap) ret.push(hashMap[key]);
3737

3838
return ret;
3939
};

0 commit comments

Comments
 (0)