spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Starting process of refactoring some formulas into categories
author
Ben Vogt <[email protected]>
date
2017-02-15 05:12:45
stats
2 file(s) changed, 35 insertions(+), 31 deletions(-)
files
src/RawFormulas/Logical.ts
src/RawFormulas/RawFormulas.ts
  1diff --git a/src/RawFormulas/Logical.ts b/src/RawFormulas/Logical.ts
  2index 7814695..54d0a90 100644
  3--- a/src/RawFormulas/Logical.ts
  4+++ b/src/RawFormulas/Logical.ts
  5@@ -124,11 +124,42 @@ var OR = function (...values) {
  6   return false;
  7 };
  8 
  9+/**
 10+ * Exclusive or or exclusive disjunction is a logical operation that outputs true only when inputs differ.
 11+ * @param values to check for exclusivity.
 12+ * @returns {boolean} returns true if only one input is considered logically true.
 13+ * @constructor
 14+ */
 15+var XOR = function (...values) {
 16+  checkArgumentsAtLeastLength(values, 1);
 17+  var alreadyTruthy = false;
 18+  for (var i = 0; i < values.length; i++) {
 19+    if (values[i] instanceof Array) {
 20+      if (values[i].length === 0) {
 21+        throw new CellError(ERRORS.REF_ERROR, "Reference does not exist.");
 22+      }
 23+      if (XOR.apply(this, values[i])) {
 24+        if (alreadyTruthy) {
 25+          return false;
 26+        }
 27+        alreadyTruthy = true;
 28+      }
 29+    } else if (valueToBoolean(values[i])) {
 30+      if (alreadyTruthy) {
 31+        return false;
 32+      }
 33+      alreadyTruthy = true;
 34+    }
 35+  }
 36+  return alreadyTruthy;
 37+};
 38+
 39 export {
 40   AND,
 41   EXACT,
 42   TRUE,
 43   FALSE,
 44   NOT,
 45-  OR
 46+  OR,
 47+  XOR
 48 }
 49\ No newline at end of file
 50diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 51index 12d9734..37dccd7 100644
 52--- a/src/RawFormulas/RawFormulas.ts
 53+++ b/src/RawFormulas/RawFormulas.ts
 54@@ -48,7 +48,8 @@ import {
 55   TRUE,
 56   FALSE,
 57   NOT,
 58-  OR
 59+  OR,
 60+  XOR
 61 } from "./Logical";
 62 import {
 63   CHAR,
 64@@ -448,36 +449,6 @@ var SUMIF = function (...values) {
 65   return sum;
 66 };
 67 
 68-/**
 69- * Exclusive or or exclusive disjunction is a logical operation that outputs true only when inputs differ.
 70- * @param values to check for exclusivity.
 71- * @returns {boolean} returns true if only one input is considered logically true.
 72- * @constructor
 73- */
 74-var XOR = function (...values) {
 75-  checkArgumentsAtLeastLength(values, 1);
 76-  var alreadyTruthy = false;
 77-  for (var i = 0; i < values.length; i++) {
 78-    if (values[i] instanceof Array) {
 79-      if (values[i].length === 0) {
 80-        throw new CellError(ERRORS.REF_ERROR, "Reference does not exist.");
 81-      }
 82-      if (XOR.apply(this, values[i])) {
 83-        if (alreadyTruthy) {
 84-          return false;
 85-        }
 86-        alreadyTruthy = true;
 87-      }
 88-    } else if (valueToBoolean(values[i])) {
 89-      if (alreadyTruthy) {
 90-        return false;
 91-      }
 92-      alreadyTruthy = true;
 93-    }
 94-  }
 95-  return alreadyTruthy;
 96-};
 97-
 98 export {
 99   __COMPLEX,
100