diff --git a/src/set/setf.ts b/src/set/setf.ts new file mode 100644 index 0000000000..b653da3de4 --- /dev/null +++ b/src/set/setf.ts @@ -0,0 +1,20 @@ +export class setf { + /** + * Creates and returns copy of the minuend with values from the subtrahend + * removed. + * + * ``` + * // Returns new Set(['b']); + * setf.subtract(new Set(['a', 'b', 'c']), new Set(['a', 'c'])); + * ``` + */ + static subtract(minuend: Set, subtrahend: Set): Set { + const result = new Set(); + minuend.forEach((value) => { + if (!subtrahend.has(value)) { + result.add(value); + } + }); + return result; + } +}