Skip to content

Commit

Permalink
refactor: Update setDifference to use ValueMap
Browse files Browse the repository at this point in the history
  • Loading branch information
kofrasa committed Oct 22, 2024
1 parent 0d5d86c commit acc5647
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/operators/expression/set/setDifference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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());
};

0 comments on commit acc5647

Please sign in to comment.