Skip to content

Commit 9beba24

Browse files
committed
feat<grease>: use Deno lint.
1 parent 7b952ee commit 9beba24

7 files changed

+60
-48
lines changed

.prettierrc

-5
This file was deleted.

deno.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"fmt": {
3+
"indentWidth": 2,
4+
"semiColons": false,
5+
"singleQuote": true,
6+
"proseWrap": "preserve",
7+
"include": [
8+
"src/"
9+
],
10+
"exclude": []
11+
},
12+
"lint": {
13+
"rules": {
14+
"exclude": [
15+
"no-extra-semi"
16+
]
17+
}
18+
}
19+
}

src/bubbleSort.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
function bubbleSort(arr: number[]) {
2-
for(let i = 0; i < arr.length; i++) {
3-
for(let j = i + 1; j < arr.length; j++) {
4-
if(arr[i] > arr[j]) {
5-
const temp = arr[i]
6-
arr[i] = arr[j]
7-
arr[j] = temp
8-
}
9-
}
10-
}
11-
console.log(arr)
12-
return arr
2+
for (let i = 0; i < arr.length; i++) {
3+
for (let j = i + 1; j < arr.length; j++) {
4+
if (arr[i] > arr[j]) {
5+
;[arr[i], arr[j]] = [arr[j], arr[i]]
6+
}
7+
}
8+
}
9+
console.log(arr)
10+
return arr
1311
}
1412

1513
bubbleSort([-6, 20, 8, -2, 4])
1614

17-
// Big O = O(n^2)
15+
// Big O = O(n^2)

src/cartesianProduct.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function cartesianProduct(arr1: number[], arr2: number[]) {
1+
function cartesianProduct(arr1: number[], arr2: number[]): string[] {
22
const resultArr: string[] = []
3+
34
for (let i = 0; i < arr1.length; i++) {
45
for (let j = 0; j < arr2.length; j++) {
56
const item = `${arr1[i]}${arr2[j]}`
@@ -17,4 +18,4 @@ const arr2 = [3, 4, 5, 1, 0]
1718

1819
cartesianProduct(arr1, arr2)
1920

20-
// O(n1n2)
21+
// O(n1n2)

src/climbingStair.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
function climbingStair(n: number): number {
2-
// n > >= 0
3-
if (n <= 3) {
4-
return n
5-
}
2+
const arr = [0, 1]
3+
for (let i = 2; i < n; i++) {
4+
arr[i] = arr[i - 2] + arr[i - 1]
5+
}
66

7-
return climbingStair(n - 2) + climbingStair(n - 1)
8-
9-
// or just using for loop.
7+
return arr[n - 1]
108
}
11-
console.log(climbingStair(4))
12-
13-
// 4: 1111,121,112,211,22
9+
console.log(climbingStair(5))
1410

15-
// O(n^3)
11+
// O(n)

src/hashTable.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ class HashTable {
2121
if (!bucket || !bucket.length) {
2222
bucket = [[key, value]]
2323
} else {
24+
// find the same key
2425
const item = bucket.find(([itemKey]) => itemKey === key)
2526
if (item) {
27+
// replace
2628
item[1] = value
2729
} else {
30+
// add
2831
bucket.push([key, value])
2932
}
3033
}
@@ -53,12 +56,12 @@ class HashTable {
5356
}
5457

5558
const hashTable = new HashTable()
56-
hashTable.set("name", "liao")
59+
hashTable.set('name', 'liao')
5760

58-
console.log(hashTable.get("name"))
61+
console.log(hashTable.get('name'))
5962

60-
hashTable.set("mane", "oho")
63+
hashTable.set('mane', 'oho')
6164

62-
console.log(hashTable.get("mane"))
63-
console.log(hashTable.get("name"))
64-
console.log(hashTable.get("nae"))
65+
console.log(hashTable.get('mane'))
66+
console.log(hashTable.get('name'))
67+
console.log(hashTable.get('nae'))

src/insertionSort.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
function insertionSort(arr: number[]) {
1+
function insertionSort(arr: number[]) {
22
for (let index = 1; index < arr.length; index++) {
33
const numberToSort = arr[index]
4-
4+
55
for (let j = index - 1; j >= 0; j--) {
6-
if(arr[j] > numberToSort) {
7-
arr[j + 1] = arr[j]
8-
if(j === 0) {
9-
arr[j] = numberToSort
10-
}
11-
}else{
12-
arr[j + 1] = numberToSort
13-
break
6+
if (arr[j] > numberToSort) {
7+
arr[j + 1] = arr[j]
8+
if (j === 0) {
9+
arr[j] = numberToSort
1410
}
11+
} else {
12+
arr[j + 1] = numberToSort
13+
break
14+
}
1515
}
1616
}
1717
console.log(arr)
@@ -20,6 +20,6 @@ function insertionSort(arr: number[]) {
2020

2121
// insertionSort([200,-500, -342,-234,-234,234,-234,5,-2,-55,-542,-5666,999, -1, 0, -2,-6, 20, 8,])
2222

23-
insertionSort([-400,-300,99,100])
23+
insertionSort([99, -400, -300, 100])
2424

25-
// O(n^2)
25+
// O(n^2)

0 commit comments

Comments
 (0)