-
Notifications
You must be signed in to change notification settings - Fork 0
/
solveData.js
47 lines (38 loc) · 1.29 KB
/
solveData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const fs = require("fs");
// 将leetcode-all处理成map结构
const initDB = () => {
const leetcodeAllStr = fs.readFileSync("./origin/leetcode-all.json", "utf8");
const leetcodeAll = JSON.parse(leetcodeAllStr);
const db = {};
leetcodeAll.stat_status_pairs.forEach(pair => {
db[pair.stat.question_id] = pair;
});
fs.writeFileSync("db-init.json", JSON.stringify(db));
};
// 根据leetcode-database、leetcode-shell、leetcode-thread标记一下db中的题目的类型
const labelQuestion = () => {
const dbStr = fs.readFileSync("db-init.json", "utf8");
const db = JSON.parse(dbStr);
const files = {
database: "./origin/leetcode-database.json",
shell: "./origin/leetcode-shell.json",
thread: "./origin/leetcode-thread.json"
};
Object.keys(files).forEach(type => {
const filename = files[type];
const leetcodeDatabaseStr = fs.readFileSync(filename, "utf8");
const leetcodeDatabase = JSON.parse(leetcodeDatabaseStr);
const databaseArr = leetcodeDatabase.stat_status_pairs.map(
pair => pair.stat.question_id
);
databaseArr.forEach(item => {
db[item].type = type;
});
});
Object.keys(db).forEach(key => {
if (db[key].type === undefined) {
db[key].type = "common";
}
});
fs.writeFileSync("db.json", JSON.stringify(db));
};