Optimise getUniqueByProp
This commit is contained in:
parent
51acf6aadc
commit
598ab03fd0
|
@ -99,9 +99,15 @@ export async function getLinkDocuments(args: {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUniqueByProp(array: any[], prop: string) {
|
export function getUniqueByProp(array: any[], prop: string) {
|
||||||
return array.filter((obj, pos, arr) => {
|
const seen = new Set()
|
||||||
return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos
|
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[] {
|
export function getLinkedTableIDs(table: Table): string[] {
|
||||||
|
|
Loading…
Reference in New Issue