-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpidig.js
More file actions
51 lines (43 loc) · 1.04 KB
/
pidig.js
File metadata and controls
51 lines (43 loc) · 1.04 KB
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
/*
pidig.js
*/
const fs = require('fs');
var loaded = false;
var fname = 'pi-10000-digits.txt';
var tens = [];
function loadTenThousand() {
loaded = false;
try {
var readline = require('readline');
var instream = fs.createReadStream(fname);
var rl = readline.createInterface({
input: instream,
terminal: false,
historySize: 0,
});
rl.on('line', function(line) {
line = line.trim();
var sa = line.split(" ");
Array.prototype.push.apply(tens, sa);
});
rl.on('close', () => {
loaded = true;
console.log('loadTenThousand complete!');
});
} catch (e) {
console.log(e.message);
}
}
function isLoaded() {
return loaded;
}
// get ten digits straight from the array
function getTen(index) {
if(index < 0 || index >= tens.length){
return "";
}
return tens[index];
}
exports.isLoaded = isLoaded;
exports.loadTenThousand = loadTenThousand;
exports.getTen = getTen;