Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Logic Equations Resolver J Script
1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<script>
//****************Sugar*********************
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Function.method('inherits', function (parent) {
var d = {}, p = (this.prototype = new parent());
this.method('uber', function uber(name) {
if (!(name in d)) {
d[name] = 0;
}
var f, r, t = d[name], v = parent.prototype;
if (t) {
while (t) {
v = v.constructor.prototype;
t -= 1;
}
f = v[name];
} else {
f = p[name];
if (f == this[name]) {
f = v[name];
}
}
d[name] += 1;
r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
d[name] -= 1;
return r;
});
return this;
});
Function.method('swiss', function (parent) {
for (var i = 1; i < arguments.length; i += 1) {
var name = arguments[i];
this.prototype[name] = parent.prototype[name];
}
return this;
});
//******************************************
//*************LogicEquation object*********
2. //var resolveKeys = new Array(Equation, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T,
W, X, Y, Z);
function LogicEquation()
{
this.resolveKeys = new Array("Equation", "A", "B", "C", "D", "E", "F",
"G", "H", "I", "J", "K", "L", "M", "N",
"O", "P", "Q", "R", "S", "T", "W", "X",
"Y", "Z");
this.equationProducts = new ListOfLogicProducts();
this.strEquation;
}
LogicEquation.prototype.cons = function(value){
this.strEquation = value;
}
LogicEquation.prototype.getEquation = function(){
return this.strEquation;
}
LogicEquation.method("setEquation", function(value){
this.strEquation = value;
});
LogicEquation.method("getEquationProducts", function(){
return this.equationProducts.strLogicProducts;
});
LogicEquation.method("tokenizeEquation", function(){
this.equationProducts.cons(this.strEquation.split("+"));
});
LogicEquation.method("resolveEquationKeys", function(args){
for(var ctr=1;ctr<args.length;ctr++)
{
var eqKey = args[ctr];
var tmpRegEx = new RegExp(this.resolveKeys[ctr], "g");
this.strEquation = this.strEquation.replace(tmpRegEx, eqKey);
}
});
LogicEquation.method("resolveEquation", function(){
return this.equationProducts.resolve();
});
//***************************************************
//***************ListOfEquationProduct***************
function ListOfLogicProducts()
{
this.logicProducts = [];
this.strLogicProducts;
}
3. ListOfLogicProducts.prototype.cons = function(value){
for(var ctr=0;ctr<value.length;ctr++)
{
this.logicProducts[ctr] = new LogicProduct();
this.logicProducts[ctr].cons(value[ctr]);
}
this.strLogicProducts = value;
}
ListOfLogicProducts.method("resolve", function(){
var result = false;
for(var ctr=0;ctr<this.logicProducts.length;ctr++)
{
var tmpResult = this.logicProducts[ctr].resolve();
if(result||tmpResult == true) result = true;
else result = false;
}
return result;
});
//**************************************************
//****************LogicProduct**********************
function LogicProduct()
{
this.productElements = new ListOfProductElements()//[];
this.strProductElements;
}
LogicProduct.method("cons", function(value){
this.productElements.cons(value.replace(/^[|]$/g,""));
this.strProductElements = value;
});
LogicProduct.prototype.resolve = function(){
return this.productElements.resolve();
}
//**************************************************
//***************ListOfProductElements**************
function ListOfProductElements()
{
this.listOfElements;
this.strListOfElements;
}
ListOfProductElements.prototype.cons = function(value){
this.listOfElements = value.split("*");
this.strListOfElements = value;
}