feat: the kata machine
This commit is contained in:
commit
dc0e0e0358
20 changed files with 2771 additions and 0 deletions
70
scripts/v1
Executable file
70
scripts/v1
Executable file
|
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env node
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const src_path = path.join(__dirname, "..", "src");
|
||||
let day = 1;
|
||||
|
||||
try {
|
||||
day = +fs.readdirSync(src_path).
|
||||
filter(i => i.includes("day")).
|
||||
sort((a, b) => {
|
||||
return +b.substring(3) - a.substring(3);
|
||||
})[0].substring(3) + 1;
|
||||
|
||||
if (isNaN(day)) {
|
||||
console.log("day is nan");
|
||||
day = 1;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("error", e.message);
|
||||
console.log("day is 1");
|
||||
day = 1;
|
||||
}
|
||||
|
||||
const day_path = path.join(src_path, `day${day}`);
|
||||
try { fs.unlinkSync(day_path); } catch (e) { }
|
||||
try { fs.mkdirSync(day_path); } catch (e) { }
|
||||
|
||||
function create_class(item) {
|
||||
fs.writeFileSync(path.join(day_path, item.name), `export default class ${item.class} {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}`);
|
||||
}
|
||||
|
||||
function create_function(item) {
|
||||
fs.writeFileSync(path.join(day_path, item.name), `export default function ${item.fn}(${item.args}): ${item.return} {
|
||||
|
||||
}`);
|
||||
}
|
||||
|
||||
[{
|
||||
name: "single-linked-list.ts",
|
||||
class: "LinkedList",
|
||||
}, {
|
||||
name: "doubly-linked-list.ts",
|
||||
class: "LinkedList",
|
||||
}, {
|
||||
name: "array-list.ts",
|
||||
class: "ArrayList",
|
||||
}, {
|
||||
name: "queue.ts",
|
||||
class: "Queue",
|
||||
}, {
|
||||
name: "stack.ts",
|
||||
class: "Stack",
|
||||
}].forEach(c => create_class(c));
|
||||
|
||||
[{
|
||||
name: "insertion-sort.ts",
|
||||
fn: "insertion_sort",
|
||||
args: "arr: number[]",
|
||||
"return": "void",
|
||||
}, {
|
||||
name: "merge-sort.ts",
|
||||
fn: "merge_sort",
|
||||
args: "arr: number[]",
|
||||
"return": "void",
|
||||
}].forEach(f => create_function(f));
|
||||
Loading…
Add table
Add a link
Reference in a new issue