Skip to content

Commit

Permalink
fix command 兼容index 不是数字的题目
Browse files Browse the repository at this point in the history
  • Loading branch information
v_yongztan committed Nov 5, 2020
1 parent 4d6d7fc commit 0e83245
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion createByUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,29 @@ async function getPageInfo(url) {
}
});
const funcReg = /var\s(.*)\s=\sfunction/
const index = questionTitle.split('.')[0]
let index = questionTitle.split('.')[0]
const funcMatch = code.match(funcReg)
let funcName = ''
if (funcMatch && funcMatch.length === 2) {
funcName = funcMatch[1]
}

// 文件前缀是否数字,不是则用leetcode作为前缀
const numReg = /^[0-9]+?$/;
if (!numReg.test(index)) {
const leetCodeFileReg = new RegExp(`^leetcode_[0-9]+?_${funcName}.js$`) //;
const libDir = fs.readdirSync('lib/')
let i = 1
for (const item of libDir) {
if (item.indexOf('leetcode') === 0) {
if (leetCodeFileReg.test(item)) {
throw new Error("file may exist - " + item);
}
i++
}
}
index = `leetcode_${i}`
}
const fileName = `${index}_${funcName}.js`


Expand Down

0 comments on commit 0e83245

Please sign in to comment.