Skip to content

Commit 935bcb3

Browse files
authored
style: add prettier and format code (doocs#644)
1 parent 8384416 commit 935bcb3

File tree

492 files changed

+3540
-3220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

492 files changed

+3540
-3220
lines changed

.docsifytopdfrc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2-
contents: ["summary.md"],
3-
pathToPublic: "pdf/doocs-leetcode.pdf",
4-
pdfOptions: "<options for puppeteer.pdf()>",
5-
removeTemp: true,
6-
emulateMedia: "screen",
2+
contents: ["summary.md"],
3+
pathToPublic: "pdf/doocs-leetcode.pdf",
4+
pdfOptions: "<options for puppeteer.pdf()>",
5+
removeTemp: true,
6+
emulateMedia: "screen",
77
};

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"tabWidth": 4,
3+
"useTabs": false,
4+
"semi": true,
5+
"singleQuote": false,
6+
"TrailingCooma": "all",
7+
"bracketSpacing": true,
8+
"jsxBracketSameLine": false,
9+
"arrowParens": "avoid"
10+
}

basic/sorting/BubbleSort/BubbleSort.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ function bubbleSort(inputArr) {
88
let temp = inputArr[j];
99
inputArr[j] = inputArr[j + 1];
1010
inputArr[j + 1] = temp;
11-
swapped = true
11+
swapped = true;
1212
}
1313
}
1414
if (swapped === false) break;
1515
}
16-
return (inputArr)
16+
return inputArr;
1717
}
1818

1919
let arr = [6, 3, 2, 1, 5];
20-
console.log(bubbleSort(arr))
20+
console.log(bubbleSort(arr));

basic/sorting/InsertionSort/InsertionSort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ function insertionSort(inputArr) {
99
}
1010
inputArr[j + 1] = temp;
1111
}
12-
return (inputArr);
12+
return inputArr;
1313
}
1414

1515
let arr = [6, 3, 2, 1, 5];
16-
console.log(insertionSort(arr))
16+
console.log(insertionSort(arr));

basic/sorting/MergeSort/Main.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
var buf = '';
1+
var buf = "";
22

3-
process.stdin.on('readable', function () {
3+
process.stdin.on("readable", function () {
44
var chunk = process.stdin.read();
55
if (chunk) buf += chunk.toString();
66
});
77

88
let getInputArgs = line => {
9-
return line.split(' ').filter(s => s !== '').map(x => parseInt(x));
10-
}
9+
return line
10+
.split(" ")
11+
.filter(s => s !== "")
12+
.map(x => parseInt(x));
13+
};
1114

1215
function mergeSort(nums, left, right) {
1316
if (left >= right) {
1417
return;
1518
}
16-
19+
1720
const mid = (left + right) >> 1;
1821
mergeSort(nums, left, mid);
1922
mergeSort(nums, mid + 1, right);
@@ -38,15 +41,12 @@ function mergeSort(nums, left, right) {
3841
}
3942
}
4043

41-
42-
43-
process.stdin.on('end', function () {
44-
buf.split('\n').forEach(function (line, lineIdx) {
44+
process.stdin.on("end", function () {
45+
buf.split("\n").forEach(function (line, lineIdx) {
4546
if (lineIdx % 2 === 1) {
4647
nums = getInputArgs(line);
4748
mergeSort(nums, 0, nums.length - 1);
48-
console.log(nums.join(' '));
49+
console.log(nums.join(" "));
4950
}
50-
5151
});
52-
});
52+
});

basic/sorting/QuickSort/Main.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
var buf = '';
1+
var buf = "";
22

3-
process.stdin.on('readable', function () {
3+
process.stdin.on("readable", function () {
44
var chunk = process.stdin.read();
55
if (chunk) buf += chunk.toString();
66
});
77

88
let getInputArgs = line => {
9-
return line.split(' ').filter(s => s !== '').map(x => parseInt(x));
10-
}
9+
return line
10+
.split(" ")
11+
.filter(s => s !== "")
12+
.map(x => parseInt(x));
13+
};
1114

1215
function quickSort(nums, left, right) {
1316
if (left >= right) {
1417
return;
1518
}
16-
19+
1720
let i = left - 1;
1821
let j = right + 1;
1922
let x = nums[(left + right) >> 1];
@@ -30,15 +33,12 @@ function quickSort(nums, left, right) {
3033
quickSort(nums, j + 1, right);
3134
}
3235

33-
34-
35-
process.stdin.on('end', function () {
36-
buf.split('\n').forEach(function (line, lineIdx) {
36+
process.stdin.on("end", function () {
37+
buf.split("\n").forEach(function (line, lineIdx) {
3738
if (lineIdx % 2 === 1) {
3839
nums = getInputArgs(line);
3940
quickSort(nums, 0, nums.length - 1);
40-
console.log(nums.join(' '));
41+
console.log(nums.join(" "));
4142
}
42-
4343
});
44-
});
44+
});

basic/sorting/SelectionSort/SelectionSort.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ function selectionSort(inputArr) {
44
let j = i;
55
let min = j;
66
while (j <= len - 1) {
7-
if (inputArr[j] < inputArr[min])
8-
min = j;
7+
if (inputArr[j] < inputArr[min]) min = j;
98
j++;
109
}
1110
let temp = inputArr[i];
@@ -16,4 +15,4 @@ function selectionSort(inputArr) {
1615
}
1716

1817
let arr = [6, 3, 2, 1, 5];
19-
console.log(selectionSort(arr))
18+
console.log(selectionSort(arr));

basic/sorting/ShellSort/ShellSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ function shellSort(arr) {
1818
}
1919

2020
let arr = [6, 3, 2, 1, 5];
21-
console.log(shellSort(arr))
21+
console.log(shellSort(arr));

lcci/01.01.Is Unique/Solution.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
* @param {string} astr
33
* @return {boolean}
44
*/
5-
var isUnique = function(astr) {
5+
var isUnique = function (astr) {
66
let bitmap = 0;
77
for (let i = 0; i < astr.length; ++i) {
8-
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
8+
const pos = astr[i].charCodeAt() - "a".charCodeAt();
99
if ((bitmap & (1 << pos)) != 0) {
1010
return false;
1111
}
12-
bitmap |= (1 << pos);
12+
bitmap |= 1 << pos;
1313
}
1414
return true;
15-
};
15+
};

lcci/01.02.Check Permutation/Solution.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
* @param {string} s2
44
* @return {boolean}
55
*/
6-
var CheckPermutation = function(s1, s2) {
7-
let n1 = s1.length, n2 = s2.length;
6+
var CheckPermutation = function (s1, s2) {
7+
let n1 = s1.length,
8+
n2 = s2.length;
89
if (n1 != n2) return false;
910
let counter = {};
1011
for (let i = 0; i < n1; i++) {
11-
let cur1 = s1.charAt(i), cur2 = s2.charAt(i);
12+
let cur1 = s1.charAt(i),
13+
cur2 = s2.charAt(i);
1214
counter[cur1] = (counter[cur1] || 0) + 1;
1315
counter[cur2] = (counter[cur2] || 0) - 1;
1416
}
1517
return Object.values(counter).every(v => v == 0);
16-
};
18+
};

0 commit comments

Comments
 (0)