-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xjq
committed
Nov 16, 2022
1 parent
a366ce0
commit 0ea1b42
Showing
12 changed files
with
168 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
|
||
const [name] = process.argv.slice(2); | ||
|
||
const root = path.resolve(process.cwd(), 'question/FrontEnd'); | ||
|
||
(async function () { | ||
const templateDir = root + '/template/'; | ||
const createDir = root + '/' + name + '/'; | ||
const files = await fs.readdir(templateDir); | ||
await fs.mkdir(createDir); | ||
for (const file of files) { | ||
await fs.copyFile(templateDir + file, createDir + file); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default function f(arr) { | ||
// js api | ||
return arr.sort(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## Sort | ||
|
||
将数组按从小到大的顺序排序 | ||
|
||
输入为 数字数组 | ||
|
||
- 冒泡排序 | ||
- 选择排序 | ||
- 插入排序 | ||
- 归并排序 | ||
- 堆排序 | ||
- 快速排序 | ||
|
||
... | ||
|
||
用例 1: | ||
|
||
```js | ||
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | ||
const sortArr = sort(arr); | ||
|
||
console.log(sortArr); // [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
``` | ||
|
||
用例 2: | ||
|
||
```js | ||
const arr = [1, 9, 2, 4, 3, 7, 6, 8, 6]; | ||
const sortArr = sort(arr); | ||
|
||
console.log(sortArr); // [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
``` | ||
|
||
用例 3: | ||
|
||
```js | ||
const arr = [1, 1, 1, 3, 4, 5, 7, 6, 6, 6, 0, 0, -1]; | ||
const sortArr = sort(arr); | ||
|
||
console.log(sortArr); // [-1, 0, 0, 1, 1, 1, 3, 4, 5, 6, 6, 6, 7] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function f(arr) { | ||
return []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import assert from 'assert'; | ||
import f from './index.mjs'; | ||
|
||
const cases = [ | ||
{ | ||
Input: [], | ||
Expected: [], | ||
Message: '空数组', | ||
}, | ||
{ | ||
Input: [1, 2, 3, 4, 5, 6, 7, 8, 9], | ||
Expected: [1, 2, 3, 4, 5, 6, 7, 8, 9], | ||
Message: '已排序好的数组', | ||
}, | ||
{ | ||
Input: [1, 9, 2, 4, 3, 7, 6, 8, 5], | ||
Expected: [1, 2, 3, 4, 5, 6, 7, 8, 9], | ||
Message: '乱序数组一', | ||
}, | ||
{ | ||
Input: [1, 1, 1, 3, 4, 5, 7, 6, 6, 6, 0, 0, -1], | ||
Expected: [-1, 0, 0, 1, 1, 1, 3, 4, 5, 6, 6, 6, 7], | ||
Message: '乱序数组二-包含负数', | ||
}, | ||
]; | ||
|
||
(function () { | ||
for (let i = 0; i < cases.length; i++) { | ||
const { Input, Expected, Message } = cases[i]; | ||
let output; | ||
try { | ||
output = f(Input); | ||
assert.deepEqual(output, Expected); | ||
} catch (error) { | ||
console.log('用例 ' + String(i + 1) + ': ' + Message + ' 未通过'); | ||
if (error.code === 'ERR_ASSERTION') { | ||
console.log('Input:', JSON.stringify(Input)); | ||
console.log('Expected:', JSON.stringify(error.expected)); | ||
console.log('Received:', JSON.stringify(output)); | ||
} else { | ||
console.log(error); | ||
} | ||
break; | ||
} | ||
console.log('用例 ' + String(i + 1) + ': ' + Message + ' 通过'); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function f(arr) { | ||
return arr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## | ||
|
||
... | ||
|
||
用例 1: | ||
|
||
```js | ||
|
||
``` | ||
|
||
用例 2: | ||
|
||
```js | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function f(arr) { | ||
return []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import assert from 'assert'; | ||
import f from './index.mjs'; | ||
|
||
const cases = [ | ||
{ | ||
Input: [1, 2, 3], | ||
Expected: [1, 2, 3], | ||
Message: '...', | ||
}, | ||
]; | ||
|
||
(function () { | ||
for (let i = 0; i < cases.length; i++) { | ||
const { Input, Expected, Message } = cases[i]; | ||
let output; | ||
try { | ||
output = f(Input); | ||
assert.deepEqual(output, Expected); | ||
} catch (error) { | ||
console.log('用例 ' + String(i + 1) + ': ' + Message + ' 未通过'); | ||
if (error.code === 'ERR_ASSERTION') { | ||
console.log('Input:', JSON.stringify(Input)); | ||
console.log('Expected:', JSON.stringify(error.expected)); | ||
console.log('Received:', JSON.stringify(output)); | ||
} else { | ||
console.log(error); | ||
} | ||
break; | ||
} | ||
console.log('用例 ' + String(i + 1) + ': ' + Message + ' 通过'); | ||
} | ||
})(); |
Large diffs are not rendered by default.
Oops, something went wrong.