forked from MapComplete/MapComplete
Merge master
This commit is contained in:
commit
cc4db080aa
45 changed files with 619 additions and 812 deletions
23
src/Utils.ts
23
src/Utils.ts
|
@ -414,6 +414,29 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
return items
|
||||
}
|
||||
|
||||
/**
|
||||
* Deduplicates the given array based on some ID-properties.
|
||||
* Removes all falsey values
|
||||
* @param arr
|
||||
* @param toKey
|
||||
* @constructor
|
||||
*/
|
||||
public static DedupOnId<T>(arr: T[], toKey: ((t:T) => string) ): T[]{
|
||||
const uniq: T[] = []
|
||||
const seen = new Set<string>()
|
||||
for (const img of arr) {
|
||||
if(!img){
|
||||
continue
|
||||
}
|
||||
const k = toKey(img)
|
||||
if (!seen.has(k)) {
|
||||
seen.add(k)
|
||||
uniq.push(img)
|
||||
}
|
||||
}
|
||||
return uniq
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all duplicates in a list of strings
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue