Created
May 16, 2024 10:55
-
-
Save arekbartnik/a77e9b40193e7f2dd2917ad39d13081e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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