diff --git a/src/Logic/UIEventSource.ts b/src/Logic/UIEventSource.ts index 5beca660df..35f0f0ef85 100644 --- a/src/Logic/UIEventSource.ts +++ b/src/Logic/UIEventSource.ts @@ -669,7 +669,7 @@ export class UIEventSource extends Store implements Writable { ) } - static asBoolean(stringUIEventSource: UIEventSource) { + static asBoolean(stringUIEventSource: UIEventSource): UIEventSource { return stringUIEventSource.sync( (str) => str === "true", [], diff --git a/src/Utils.ts b/src/Utils.ts index 180c727cbc..25da56512a 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -387,19 +387,27 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be return newArr } + /** + * Finds all duplicates in a list of strings + * + * Utils.Duplicates(["a", "b", "c"]) // => [] + * Utils.Duplicates(["a", "b","c","b"] // => ["b"] + * Utils.Duplicates(["a", "b","c","b","b"] // => ["b"] + * + */ public static Duplicates(arr: string[]): string[] { if (arr === undefined) { return undefined } - const newArr = [] const seen = new Set() + const duplicates = new Set() for (const string of arr) { if (seen.has(string)) { - newArr.push(string) + duplicates.add(string) } seen.add(string) } - return newArr + return Array.from(duplicates) } /**