Skip to content

Commit c60d7e1

Browse files
committed
style: format js/ts code
1 parent 567383e commit c60d7e1

File tree

6 files changed

+25
-26
lines changed

6 files changed

+25
-26
lines changed

basic/sorting/HeapSort/Main.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function heapify(arr, n, i) {
2121
}
2222
}
2323

24-
2524
function buildHeap(arr, n) {
2625
const lastNode = n - 1;
2726
const lastParent = Math.floor((lastNode - 1) / 2);
@@ -40,6 +39,6 @@ function heapSort(arr, n) {
4039

4140
function main(arr, n, m) {
4241
heapSort(arr, n);
43-
const list = arr.slice(0, m)
42+
const list = arr.slice(0, m);
4443
console.log(list.join(' '));
4544
}

basic/sorting/MergeSort/Main.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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 => {
99
return line
10-
.split(" ")
11-
.filter(s => s !== "")
10+
.split(' ')
11+
.filter(s => s !== '')
1212
.map(x => parseInt(x));
1313
};
1414

@@ -41,12 +41,12 @@ function mergeSort(nums, left, right) {
4141
}
4242
}
4343

44-
process.stdin.on("end", function () {
45-
buf.split("\n").forEach(function (line, lineIdx) {
44+
process.stdin.on('end', function () {
45+
buf.split('\n').forEach(function (line, lineIdx) {
4646
if (lineIdx % 2 === 1) {
4747
nums = getInputArgs(line);
4848
mergeSort(nums, 0, nums.length - 1);
49-
console.log(nums.join(" "));
49+
console.log(nums.join(' '));
5050
}
5151
});
5252
});

basic/sorting/QuickSort/Main.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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 => {
99
return line
10-
.split(" ")
11-
.filter(s => s !== "")
10+
.split(' ')
11+
.filter(s => s !== '')
1212
.map(x => parseInt(x));
1313
};
1414

@@ -31,12 +31,12 @@ function quickSort(nums, left, right) {
3131
quickSort(nums, j + 1, right);
3232
}
3333

34-
process.stdin.on("end", function () {
35-
buf.split("\n").forEach(function (line, lineIdx) {
34+
process.stdin.on('end', function () {
35+
buf.split('\n').forEach(function (line, lineIdx) {
3636
if (lineIdx % 2 === 1) {
3737
nums = getInputArgs(line);
3838
quickSort(nums, 0, nums.length - 1);
39-
console.log(nums.join(" "));
39+
console.log(nums.join(' '));
4040
}
4141
});
4242
});

lcof2/剑指 Offer II 048. 序列化与反序列化二叉树/Solution.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @return {string}
1414
*/
1515
var serialize = function (root) {
16-
return rserialize(root, "");
16+
return rserialize(root, '');
1717
};
1818

1919
/**
@@ -23,23 +23,23 @@ var serialize = function (root) {
2323
* @return {TreeNode}
2424
*/
2525
var deserialize = function (data) {
26-
const dataArray = data.split(",");
26+
const dataArray = data.split(',');
2727
return rdeserialize(dataArray);
2828
};
2929

3030
const rserialize = (root, str) => {
3131
if (root === null) {
32-
str += "#,";
32+
str += '#,';
3333
} else {
34-
str += root.val + "" + ",";
34+
str += root.val + '' + ',';
3535
str = rserialize(root.left, str);
3636
str = rserialize(root.right, str);
3737
}
3838
return str;
3939
};
4040

4141
const rdeserialize = dataList => {
42-
if (dataList[0] === "#") {
42+
if (dataList[0] === '#') {
4343
dataList.shift();
4444
return null;
4545
}

lcs/LCS 02. 完成一半题目/Solution.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @param {number[]} questions
33
* @return {number}
44
*/
5-
var halfQuestions = function(questions) {
5+
var halfQuestions = function (questions) {
66
let counter = new Array(1010).fill(0);
77
for (const q of questions) {
88
++counter[q];
@@ -15,4 +15,4 @@
1515
n -= counter[i];
1616
}
1717
return ans;
18-
};
18+
};
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function fillCups(amount: number[]): number {
22
amount.sort((a, b) => a - b);
33
let [a, b, c] = amount;
4-
let diff = (a + b) - c;
4+
let diff = a + b - c;
55
if (diff <= 0) return c;
6-
else return Math.floor((diff + 1) / 2) + c;
7-
};
6+
else return Math.floor((diff + 1) / 2) + c;
7+
}

0 commit comments

Comments
 (0)