2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
33
Task/Ternary-logic/JavaScript/ternary-logic-1.js
Normal file
33
Task/Ternary-logic/JavaScript/ternary-logic-1.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
var L3 = new Object();
|
||||
|
||||
L3.not = function(a) {
|
||||
if (typeof a == "boolean") return !a;
|
||||
if (a == undefined) return undefined;
|
||||
throw("Invalid Ternary Expression.");
|
||||
}
|
||||
|
||||
L3.and = function(a, b) {
|
||||
if (typeof a == "boolean" && typeof b == "boolean") return a && b;
|
||||
if ((a == true && b == undefined) || (a == undefined && b == true)) return undefined;
|
||||
if ((a == false && b == undefined) || (a == undefined && b == false)) return false;
|
||||
if (a == undefined && b == undefined) return undefined;
|
||||
throw("Invalid Ternary Expression.");
|
||||
}
|
||||
|
||||
L3.or = function(a, b) {
|
||||
if (typeof a == "boolean" && typeof b == "boolean") return a || b;
|
||||
if ((a == true && b == undefined) || (a == undefined && b == true)) return true;
|
||||
if ((a == false && b == undefined) || (a == undefined && b == false)) return undefined;
|
||||
if (a == undefined && b == undefined) return undefined;
|
||||
throw("Invalid Ternary Expression.");
|
||||
}
|
||||
|
||||
// A -> B is equivalent to -A or B
|
||||
L3.ifThen = function(a, b) {
|
||||
return L3.or(L3.not(a), b);
|
||||
}
|
||||
|
||||
// A <=> B is equivalent to (A -> B) and (B -> A)
|
||||
L3.iff = function(a, b) {
|
||||
return L3.and(L3.ifThen(a, b), L3.ifThen(b, a));
|
||||
}
|
||||
10
Task/Ternary-logic/JavaScript/ternary-logic-2.js
Normal file
10
Task/Ternary-logic/JavaScript/ternary-logic-2.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
L3.not(true) // false
|
||||
L3.not(var a) // undefined
|
||||
|
||||
L3.and(true, a) // undefined
|
||||
|
||||
L3.or(a, 2 == 3) // false
|
||||
|
||||
L3.ifThen(true, a) // undefined
|
||||
|
||||
L3.iff(a, 2 == 2) // undefined
|
||||
Loading…
Add table
Add a link
Reference in a new issue