Docs: improve documentation of duplicates and UIEventSource
This commit is contained in:
parent
a9bfe4f37b
commit
b7a88ced70
2 changed files with 12 additions and 4 deletions
|
@ -669,7 +669,7 @@ export class UIEventSource<T> extends Store<T> implements Writable<T> {
|
|||
)
|
||||
}
|
||||
|
||||
static asBoolean(stringUIEventSource: UIEventSource<string>) {
|
||||
static asBoolean(stringUIEventSource: UIEventSource<string>): UIEventSource<boolean> {
|
||||
return stringUIEventSource.sync(
|
||||
(str) => str === "true",
|
||||
[],
|
||||
|
|
14
src/Utils.ts
14
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<string>()
|
||||
const duplicates = new Set<string>()
|
||||
for (const string of arr) {
|
||||
if (seen.has(string)) {
|
||||
newArr.push(string)
|
||||
duplicates.add(string)
|
||||
}
|
||||
seen.add(string)
|
||||
}
|
||||
return newArr
|
||||
return Array.from(duplicates)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue