-
Notifications
You must be signed in to change notification settings - Fork 1
/
calcb.js
47 lines (39 loc) · 915 Bytes
/
calcb.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
//6+4+2+1+3=16
//6+4+2+1-3=10
//6+4+2-1=11
//6+4-2=8
//6-4=2
var res = new Int16Array([16,10,11,8,2]),l= res.length;
var variables = [];
(function calculate(i) {
if(i === l-1) {
variables[i] = res[i];
console.log(i + ":" + variables[i]);
process.exit();
}else {
calculateTail(res[i],res[i+1],function(tail) {
variables[i] = tail;
calculateHead(res[i],res[i+1],function(head) {
res[i+1] = head;
console.log('-----------------'+i+'-----------------')
calculate(i+1);
});
});
}
})(0);
function calculateTail(x,y,cb) {
console.log("calculate tail:("+ x + "," + y + ")");
setTimeout(function(){
var tail = (x-y)/2;
console.log("tail:" + tail);
cb(tail);
},300);
}
function calculateHead(x,y,cb) {
console.log("calculate head:("+ x + "," + y + ")");
setTimeout(function(){
var head = (x+y)/2;
console.log("head:" + head);
cb(head);
},400);
}