mirror of
https://github.com/neocities/neocities.git
synced 2025-08-03 08:11:56 +02:00
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
/*---------------------------------------------------------------------------------------------
|
|
* 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;
|
|
}
|