-
Notifications
You must be signed in to change notification settings - Fork 2
/
noOfTimes.js
77 lines (74 loc) · 2.1 KB
/
noOfTimes.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fsp = require('fs').promises;
const path = require('path')
// Count the no of appearance of orgs in GSOC since 2009
const getArrayofTitle = async() => {
const list = []
let fileData = await fsp.readFile(path.resolve(__dirname, 'orgs2.json'))
let obj = JSON.parse(fileData)
const listYears = [
'list2009',
'list2010',
'list2011',
'list2012',
'list2013',
'list2014',
'list2015',
'list2016',
'list2017',
'list2018',
'list2019'
]
listYears.forEach( listYear => {
let len = obj[`${listYear}`].length
for(let i=0; i<len; i++){
list.push({
title: obj[`${listYear}`][i].title,
year: listYear.substring(4,)
})
}
})
function compare(a,b) {
if(a.title < b.title){
return -1
} else if(a.title > b.title){
return 1
}
return 0
}
list.sort( compare )
let len = list.length
let match = list[0].title.trim().split(' ').join('').toLowerCase()
let year = list[0].year
let count = 1
const ob = {}
var yrList = [year]
for(let i=1;i<len;i++){
let str = list[i].title.trim().split(' ').join('').toLowerCase()
let yr = list[i].year
if(str === match){
count++
yrList.push(yr)
} else{
ob[`${match}`] = {
count,
yrList: yrList
}
match = str
count = 1
yrList= [yr]
}
}
listYears.forEach(listYear => {
let len = obj[`${listYear}`].length
for(var i=0 ;i<len;i++){
let titleTrim = obj[`${listYear}`][i].title.trim().split(' ').join('').toLowerCase()
if(ob[titleTrim] != null){
obj[`${listYear}`][i][`noOfTimes`] = ob[titleTrim].count
obj[`${listYear}`][i][`yrList`] = ob[titleTrim].yrList
}
}
})
console.log(obj)
await fsp.writeFile(path.resolve(__dirname, 'orgs2.json'), JSON.stringify(obj));
}
getArrayofTitle()