Optimise getUniqueByProp

This commit is contained in:
Sam Rose 2023-12-14 10:40:22 +00:00
parent 51acf6aadc
commit 598ab03fd0
No known key found for this signature in database
1 changed files with 9 additions and 3 deletions

View File

@ -99,9 +99,15 @@ export async function getLinkDocuments(args: {
}
export function getUniqueByProp(array: any[], prop: string) {
return array.filter((obj, pos, arr) => {
return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos
})
const seen = new Set()
const ret = []
for (const item of array) {
if (!seen.has(item[prop])) {
seen.add(item[prop])
ret.push(item)
}
}
return ret
}
export function getLinkedTableIDs(table: Table): string[] {