-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathtest.js
More file actions
38 lines (33 loc) · 914 Bytes
/
test.js
File metadata and controls
38 lines (33 loc) · 914 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
27
28
29
30
31
32
33
34
35
36
37
38
function main(text) {
var jobj = JSON.parse(text);
var coordinates = jobj['coordinates'];
var len = coordinates.length;
var x = 0;
var y = 0;
var z = 0;
for (var i = 0; i < coordinates.length; i++) {
coord = coordinates[i];
x += coord['x'];
y += coord['y'];
z += coord['z'];
}
console.log(x / len);
console.log(y / len);
console.log(z / len);
}
function notify(msg) {
return new Promise(resolve => {
const client = require('net').connect(9001, 'localhost', () => {
client.end(msg, 'utf8', () => {
client.destroy();
resolve();
});
}).on('error', resolve);
});
}
(async function() {
const text = require('fs').readFileSync("/tmp/1.json", "utf8");
await notify(`Node.js\t${require('process').pid}`);
main(text);
await notify('stop');
})();