chore(utils): Move generic utils from region module to utils (#6466)

Moves some generic utilities from the region module to the top-level utils package
This commit is contained in:
Stevche Radevski
2024-02-22 08:06:46 +00:00
committed by GitHub
parent 5a15e039ec
commit add861d205
6 changed files with 68 additions and 24 deletions
@@ -0,0 +1,16 @@
// 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
// Revisit if there is such use-case in the future
export const getDuplicates = (collection: string[]): string[] => {
const uniqueElements = new Set<string>()
const duplicates = new Set<string>()
collection.forEach((item) => {
if (uniqueElements.has(item)) {
duplicates.add(item)
} else {
uniqueElements.add(item)
}
})
return Array.from(duplicates)
}