-
Notifications
You must be signed in to change notification settings - Fork 0
/
bestchar.js
51 lines (46 loc) · 1.19 KB
/
bestchar.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
const jsonfile = require('jsonfile');
let chararr = [];
let stararr = [];
let sendarr = [];
jsonfile.readFile("characters.json", function (err, obj) {
for (let i in obj.articles) {
chararr.push(obj.articles[i].title);
}
chararr = chararr.sort();
getbestactorarr(chararr);
readstararr();
});
function getbestactorarr(arr) {
let current = arr[0];
let count = 0;
for (let i in arr) {
if (current == arr[i]) {
count++;
}
else {
stararr.push([current, count]);
current = arr[i];
count = 1;
}
}
stararr.sort(function (a, b) {
return b[1] - a[1];
});
}
function readstararr() {
for (let i in stararr) {
if (stararr[i][1] == 1) {
}
else if(stararr[i][1] == 2)
{
sendarr.push({ key: stararr[i][1],parent: 2, name: stararr[i][0] });
}
else {
sendarr.push({ key: stararr[i][1], parent: `${stararr[i][1] - 1}`, name: stararr[i][0] });
}
}
jsonfile.writeFile('gitbook.json', {act: sendarr}, { spaces: 2}, () => {
//console.error(err);
});
console.log(sendarr);
}