Raw
1 // This function is intentionally not generic, as we will likely need a comparator function in that case, which will make it more complex than necessary
2 // Revisit if there is such use-case in the future
3 export const getDuplicates = (collection: string[]): string[] => {
4 const uniqueElements = new Set<string>()
5 const duplicates = new Set<string>()
6
7 collection.forEach((item) => {
8 if (uniqueElements.has(item)) {
9 duplicates.add(item)
10 } else {
11 uniqueElements.add(item)
12 }
13 })
14
15 return Array.from(duplicates)
16 }