|
|
@@ -21,7 +21,8 @@ var SetDifferenceExpression = module.exports = function SetDifferenceExpression(
|
|
|
|
|
|
// DEPENDENCIES
|
|
|
var Value = require("../Value"),
|
|
|
- Expression = require("./Expression");
|
|
|
+ Expression = require("./Expression"),
|
|
|
+ Helpers = require("./Helpers")
|
|
|
|
|
|
// PROTOTYPE MEMBERS
|
|
|
proto.getOpName = function getOpName() {
|
|
|
@@ -29,23 +30,26 @@ proto.getOpName = function getOpName() {
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Takes 2 arrays. Assigns the second array to the first array.
|
|
|
+ * Takes 2 arrays. Returns the difference
|
|
|
* @method evaluateInternal
|
|
|
**/
|
|
|
proto.evaluateInternal = function evaluateInternal(vars) {
|
|
|
- var array1 = this.operands[0].evaluateInternal(vars),
|
|
|
- array2 = this.operands[1].evaluateInternal(vars);
|
|
|
- if (array1 instanceof Array) throw new Error(this.getOpName() + ": object 1 must be an array. Got a(n): " + typeof array1);
|
|
|
- if (array2 instanceof Array) throw new Error(this.getOpName() + ": object 2 must be an array. Got a(n): " + typeof array2);
|
|
|
+ var lhs = this.operands[0].evaluateInternal(vars),
|
|
|
+ rhs = this.operands[1].evaluateInternal(vars);
|
|
|
|
|
|
- var returnVec = [];
|
|
|
+ if (lhs instanceof Array) throw new Error(this.getOpName() + ": object 1 must be an array. Got a(n): " + typeof lhs);
|
|
|
+ if (rhs instanceof Array) throw new Error(this.getOpName() + ": object 2 must be an array. Got a(n): " + typeof rhs);
|
|
|
|
|
|
- array1.forEach(function(key) {
|
|
|
- if (-1 === array2.indexOf(key)) {
|
|
|
+ var rhsSet = Helpers.arrayToSet(rhs),
|
|
|
+ returnVec = [];
|
|
|
+
|
|
|
+ lhs.forEach(function(key) {
|
|
|
+ if (-1 === rhsSet.indexOf(key)) {
|
|
|
returnVec.push(key);
|
|
|
}
|
|
|
}, this);
|
|
|
- return returnVec;
|
|
|
+
|
|
|
+ return Value.consume(returnVec);
|
|
|
};
|
|
|
|
|
|
/** Register Expression */
|