deduction
Version:
deduction
45 lines (41 loc) • 1.07 kB
JavaScript
'use strict';
var cal = require('./extend.js');
class Claim {
constructor(p, q, count) {
switch((p instanceof Claim)*2+(q instanceof Claim)) {
case 3:
this.p = p.assign(q.p);
this.q = cal(p.q, q.q);
this.count = p.count+q.count;
break;
case 2:
this.p = p.p;
this.q = cal(p.q, q);
this.count = p.count;
break;
case 1:
this.p = q.assign(p);
this.q = q.q;
this.count = q.count;
break;
case 0:
this.p = p;
this.q = q;
this.count = count || 0;
}
}
assign(p) {
var _p = Object.assign({}, p);
for(var n in this.p) {
var u = p[n], v = this.p[n];
_p[n] = u ? s => cal(u, s) && cal(v, s) : v;
}
return _p;
}
argc(maxCount) {
var argc = Object.keys(this.p).length;
if(argc < maxCount-this.count) return -1;
return argc;
}
}
module.exports = Claim;