forked from BuonOmo/polyfinal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbounds.js
More file actions
26 lines (21 loc) · 811 Bytes
/
bounds.js
File metadata and controls
26 lines (21 loc) · 811 Bytes
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
/**
* This takes the data already altered and add lower bound and upper bound components,
* see issue #4 on https://github.com/buonomo/polyfinal.
*/
var fs = require("fs")
var vm = require('vm')
var filename="../js/data.js"
var content = fs.readFileSync(filename)
vm.runInThisContext(content) // this adds `finals` variable
var withBounds = finals.map((el, i, self) =>{
if (self[i+1] && el.id === self[i+1].id && el.section === self[i+1].section){
el.upperBound = self[i+1].names[0];
} else if (self[i -1] && el.id === self[i-1].id && el.section == self[i-1].section) {
el.lowerBound = self[i-1].names[1];
}
return el
});
fs.writeFile('js/new_data.js', "var finals="+JSON.stringify(withBounds), 'utf8', (err) => {
if (err) throw err;
console.log('file js/new_data.js saved')
});