Merge pull request #12580 from Budibase/optimise-get-unique-by-prod
Optimise getUniqueByProp
This commit is contained in:
commit
aaedaacf9d
|
@ -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 filteredArray = []
|
||||||
})
|
for (const item of array) {
|
||||||
|
if (!seen.has(item[prop])) {
|
||||||
|
seen.add(item[prop])
|
||||||
|
filteredArray.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredArray
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLinkedTableIDs(table: Table): string[] {
|
export function getLinkedTableIDs(table: Table): string[] {
|
||||||
|
|
Loading…
Reference in New Issue