-
Notifications
You must be signed in to change notification settings - Fork 0
/
createReadme.js
52 lines (41 loc) · 1.27 KB
/
createReadme.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
48
49
50
51
52
const fs = require('fs');
const exec = require('child_process').exec;
const path = process.cwd() + '/js';
var title = `#### This is leetcode solution with js.
I have done some explaination for some leetcode problems.
You can visit https://qiuyuntao.github.io/leetcode to see these explainations.
`;
fs.readdir(path, (err, files) => {
var array = [[
'problems',
'explaination',
'source'
], [
'-------------------------------------------',
':-------------------------------------------:',
'-------------------------------------------:'
]];
files.sort((a, b) => {
var c = Number(/\d+/.exec(a)[0]);
var d = Number(/\d+/.exec(b)[0]);
return c - d;
});
files.map((d) => {
var number = /\d+/.exec(d)[0];
var name = d.replace('.js', '');
var url = name.replace(/\d+\./, '');
url = url.trim().toLowerCase();
url = url.split(' ');
url = url.join('-');
array.push([
`[${name}](https://leetcode.com/problems/${url}/)`,
`[view explaination](http://qiuyuntao.github.io/leetcode/solution/${number}.html)`,
`[view source](./js/${name}.js)`
]);
var arr = array.map((data) => {
return '|' + data.join('|') + '|';
});
fs.writeFile('./readme.md', title + arr.join('\n'), () => {
})
});
});