瀏覽代碼

EAGLESIX-2713: port -testcases

Jake Delaney 11 年之前
父節點
當前提交
525eee4460
共有 1 個文件被更改,包括 14 次插入10 次删除
  1. 14 10
      lib/pipeline/expressions/SetDifferenceExpression.js

+ 14 - 10
lib/pipeline/expressions/SetDifferenceExpression.js

@@ -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 */