Skip to content

Instantly share code, notes, and snippets.

@arekbartnik
Created May 16, 2024 10:55
Show Gist options
  • Save arekbartnik/a77e9b40193e7f2dd2917ad39d13081e to your computer and use it in GitHub Desktop.
Save arekbartnik/a77e9b40193e7f2dd2917ad39d13081e to your computer and use it in GitHub Desktop.
import { FileWithPath } from "react-dropzone-esm";
function hasFileWithName(set: Set<FileWithPath>, name: string) {
return [...set].some((file) => file.name === name);
}
export function combineUniqueFileSets<T extends FileWithPath>(set1: Set<T>, set2: Set<T>): Set<T> {
const combinedSet = new Set<T>();
// Add all elements from set1 to the combinedSet
for (const item of set1) {
combinedSet.add(item);
}
// Add all elements from set2 to the combinedSet
for (const item of set2) {
if (!hasFileWithName(set1, item.name)) {
combinedSet.add(item);
}
}
return combinedSet;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment