diff --git a/src/operators/expression/set/setDifference.ts b/src/operators/expression/set/setDifference.ts index ed62c84b..248e9abd 100644 --- a/src/operators/expression/set/setDifference.ts +++ b/src/operators/expression/set/setDifference.ts @@ -4,7 +4,7 @@ import { computeValue, ExpressionOperator, Options } from "../../../core"; import { Any, AnyObject } from "../../../types"; -import { notInArray } from "../../../util"; +import { ValueMap } from "../../../util"; /** * Returns elements of a set that do not appear in a second set. @@ -17,5 +17,8 @@ export const $setDifference: ExpressionOperator = ( options: Options ): Any => { const args = computeValue(obj, expr, null, options) as Any[][]; - return args[0].filter(v => notInArray(args[1], v)); + const m = ValueMap.init(options.hashFunction); + args[0].forEach(v => m.set(v, true)); + args[1].forEach(v => m.delete(v)); + return Array.from(m.keys()); };