UNPKG

nope-js-node

Version:

NoPE Runtime for Nodejs. For Browser-Support please use nope-browser

70 lines (69 loc) 1.83 kB
"use strict"; /** * @author Martin Karkowski * @email m.karkowski@zema.de * @desc [description] */ Object.defineProperty(exports, "__esModule", { value: true }); exports.difference = exports.union = exports.determineDifference = void 0; /** * Helper Function which will determine the Difference between set01 and set02. * If values are in set02 and not in set01 they will be putted into added. If * items are in set01 but not in set02 they will be added to removed. * * @export * @template T * @param {Set<T>} set01 Base Set * @param {Set<T>} set02 Set to compare it with * @return {*} */ function determineDifference(set01, set02) { const added = new Set(); const removed = new Set(); // We iterate over the set01 and // set02. If elements of set01 arent // present in set02 => they have been // removed for (const item of set01) { if (!set02.has(item)) { removed.add(item); } } // If elements of set02 arent // present in set01 => they have been // added for (const item of set02) { if (!set01.has(item)) { added.add(item); } } return { added, removed, }; } exports.determineDifference = determineDifference; /** * Unions the two sets * @param {Set<T>} set01 * @param {Set<T>} set01 * @returns */ function union(set01, set02) { return new Set([...set01, ...set02]); } exports.union = union; /** * Substracts set02 from set01 * @param {Set<T>} set01 Base Set * @param {Set<T>} set02 The Set to substract * @returns */ function difference(set01, set02) { const diff = new Set([...set01]); for (const s of set02) { diff.delete(s); } return diff; } exports.difference = difference;