Skip to content

Commit c1d7d66

Browse files
fix: resolve lint issues so the project is clean (#98)
2 parents 96a9cfd + dcbe0d1 commit c1d7d66

File tree

6 files changed

+58
-50
lines changed

6 files changed

+58
-50
lines changed

DesignDataStructure/designI.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ The data structure should be efficient enough to accommodate the operations acco
2121
Frequency: Least frequent.
2222
*/
2323

24+
/*
25+
example:
2426
2527
class effStructure {
2628
this.maxHeap = [];
@@ -33,4 +35,5 @@ class effStructure {
3335
3) deleteMin(): O(log N)
3436
4) deleteMax(): O(log N)
3537
5) Insert(log N)
36-
6) Delete: O(log N)
38+
6) Delete: O(log N)
39+
*/

Maximal_square.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ Output: 0
2525
var maximalSquare = function(matrix) {
2626
var m = matrix.length;
2727
var n = (matrix[0] || []).length;
28-
var dp = Array(m).fill(0).map(_ => Array(n));
28+
var dp = Array(m).fill(0).map(() => Array(n));
2929
var max = 0;
3030

3131
for (var k = 0; k < m; k++) {
32-
dp[k][0] = matrix[k][0] === '1' ? 1 : 0;
32+
dp[k][0] = matrix[k][0] === "1" ? 1 : 0;
3333
max = Math.max(max, dp[k][0]);
3434
}
3535

3636
for (var p = 0; p < n; p++) {
37-
dp[0][p] = matrix[0][p] === '1' ? 1 : 0;
37+
dp[0][p] = matrix[0][p] === "1" ? 1 : 0;
3838
max = Math.max(max, dp[0][p]);
3939
}
4040

4141
for (var i = 1; i < m; i++) {
4242
for (var j = 1; j < n; j++) {
43-
if (matrix[i][j] === '1') {
43+
if (matrix[i][j] === "1") {
4444
dp[i][j] = Math.min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1;
4545
max = Math.max(max, dp[i][j]);
4646
} else {
@@ -52,3 +52,5 @@ var maximalSquare = function(matrix) {
5252
return max * max;
5353

5454
};
55+
56+
module.exports.maximalSquare = maximalSquare;

Maximal_square_Test.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const assert = require('assert');
2-
const {Maximalsquare } = require('../LeetcodeProblems/Maximal_square');
1+
const assert = require("assert");
2+
const {Maximalsquare } = require("../LeetcodeProblems/Maximal_square");
33

44
function test1() {
55
var matrix = [
66
[1, 0, 1, 0, 0],
77
[1, 0, 1, 1, 1],
8-
[1, 1, 1, 1 1],
8+
[1, 1, 1, 1, 1],
99
[1, 0, 0, 1, 0],
10-
]
10+
];
1111

1212
assert.strictEqual(Maximalsquare(matrix), 4);
1313
}
@@ -16,16 +16,17 @@ function test2() {
1616
var matrix = [
1717
[0, 1],
1818
[1,0]
19-
]
19+
];
2020

2121
assert.strictEqual(Maximalsquare(matrix), 1);
2222
}
2323

2424
function test3(){
2525
var matrix = [
2626
[0]
27-
]
28-
assert.strictEqual(Maximalsquare(matrix), 0);
27+
];
28+
29+
assert.strictEqual(Maximalsquare(matrix), 0);
2930
}
3031

3132
function test() {
@@ -34,4 +35,4 @@ function test() {
3435
test3();
3536
}
3637

37-
module.exports.test = test
38+
module.exports.test = test;

SortingAlgorithms/QuickSort.js

+30-29
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
function swap(items, leftIndex, rightIndex){
2-
var temp = items[leftIndex];
3-
items[leftIndex] = items[rightIndex];
4-
items[rightIndex] = temp;
2+
var temp = items[leftIndex];
3+
items[leftIndex] = items[rightIndex];
4+
items[rightIndex] = temp;
55
}
66
function partition(items, left, right) {
7-
var pivot = items[Math.floor((right + left) / 2)], //middle element
8-
i = left, //left pointer
9-
j = right; //right pointer
10-
while (i <= j) {
11-
while (items[i] < pivot) {
12-
i++;
13-
}
14-
while (items[j] > pivot) {
15-
j--;
16-
}
17-
if (i <= j) {
18-
swap(items, i, j); //sawpping two elements
19-
i++;
20-
j--;
21-
}
7+
var pivot = items[Math.floor((right + left) / 2)], //middle element
8+
i = left, //left pointer
9+
j = right; //right pointer
10+
while (i <= j) {
11+
while (items[i] < pivot) {
12+
i++;
2213
}
23-
return i;
14+
while (items[j] > pivot) {
15+
j--;
16+
}
17+
if (i <= j) {
18+
swap(items, i, j); //sawpping two elements
19+
i++;
20+
j--;
21+
}
22+
}
23+
return i;
2424
}
2525

2626
function quickSort(items, left, right) {
27-
var index;
28-
if (items.length > 1) {
29-
index = partition(items, left, right); //index returned from partition
30-
if (left < index - 1) { //more elements on the left side of the pivot
31-
quickSort(items, left, index - 1);
32-
}
33-
if (index < right) { //more elements on the right side of the pivot
34-
quickSort(items, index, right);
35-
}
27+
var index;
28+
if (items.length > 1) {
29+
index = partition(items, left, right); //index returned from partition
30+
if (left < index - 1) { //more elements on the left side of the pivot
31+
quickSort(items, left, index - 1);
32+
}
33+
if (index < right) { //more elements on the right side of the pivot
34+
quickSort(items, index, right);
3635
}
37-
return items;
36+
}
37+
return items;
3838
}
3939

40+
module.exports.quickSort = quickSort;

SortingAlgorithms/heapSort.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
// Testing Gist
22
var heapSort = function(arr) {
33
var n = arr.length;
4-
for(var i = Math.floor(n/2) - 1; i >= 0; i--)
4+
for(let i = Math.floor(n/2) - 1; i >= 0; i--) {
55
heapify(arr, n, i);
6+
}
67

7-
for(var i = n - 1; i >= 0; i--) {
8+
for(let i = n - 1; i >= 0; i--) {
89
swap(arr, 0, i);
910
heapify(arr, i, 0);
1011
}
1112

1213
return arr;
13-
}
14+
};
1415

1516
var heapify = function(arr, n, i) {
1617
var left = 2 * i + 1;
@@ -32,17 +33,17 @@ var heapify = function(arr, n, i) {
3233
swap(arr, i, right);
3334
heapify(arr, n, right);
3435
}
35-
}
36+
};
3637

3738
var swap = function(arr, a, b) {
3839
var temp = arr[a];
3940
arr[a] = arr[b];
4041
arr[b] = temp;
41-
}
42+
};
4243

4344
console.log(heapSort([14, 1, 10, 2, 3, 5, 6, 4, 7, 11, 12, 13]));
4445
console.log(heapSort([]));
4546
console.log(heapSort([1]));
4647
console.log(heapSort([2, 1]));
47-
console.log(heapSort([1,7,2,3,4,1,10,2,3,4,5]))
48+
console.log(heapSort([1,7,2,3,4,1,10,2,3,4,5]));
4849

utilsClasses/ListNodeTestHelper.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const assert = require('assert');
1+
const assert = require("assert");
22

33
var assertList = function(list, expectedArr) {
44
const listlength = list ? list.length() : 0;
@@ -7,6 +7,6 @@ var assertList = function(list, expectedArr) {
77
assert.strictEqual(list.val, expectedArr[i]);
88
list = list.next;
99
}
10-
}
10+
};
1111

1212
module.exports.assertList = assertList;

0 commit comments

Comments
 (0)