UNPKG

monaco-editor-core

Version:

A browser based code editor

36 lines (35 loc) 1.12 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ export function diffSets(before, after) { const removed = []; const added = []; for (const element of before) { if (!after.has(element)) { removed.push(element); } } for (const element of after) { if (!before.has(element)) { added.push(element); } } return { removed, added }; } /** * Computes the intersection of two sets. * * @param setA - The first set. * @param setB - The second iterable. * @returns A new set containing the elements that are in both `setA` and `setB`. */ export function intersection(setA, setB) { const result = new Set(); for (const elem of setB) { if (setA.has(elem)) { result.add(elem); } } return result; }