-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
48 lines (40 loc) · 948 Bytes
/
common.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
'use strict';
var fs = require('fs');
var exports = {
loadData: loadData,
};
/**
* @param {Object} err - err
* @param {Object[]} files - test
*/
function processDir(err, files) {
this.filesToProcess = files.length;
this.numProcessed = 0;
this.dataSets = [];
files.map(function(filePath, fileIndex) {
fs.readFile('inputs/' + filePath, 'utf-8', processData);
}, this);
}
function processData(err, data) {
this.dataSets.push(data.split('\n'));
this.numProcessed++;
if (this.numProcessed === this.filesToProcess) {
delete exports.loadData;
exports.readLine = function() {
var lineToReturn = this.dataSets[this.currSet][0];
data[this.currSet].splice(0, 1);
return lineToReturn;
};
exports.useSet = function(i) {
this.currSet = i;
};
}
}
function loadData(cb) {
fs.readdir('inputs', processDir);
}
module.exports = function(cb) {
return {
loadData: loadData,
};
};