Standard Library Utilities
Set
Set stores unique values and ignores duplicates.
Set
A `Set<T>` keeps only one copy of each value.
Set
set.ts
Replay: real traced execution (multi-file project)
const extraTag: string = "typed";
const tags: Set<string> = new Set<string>(["typed", "web"]);
tags.add(extraTag);
tags.add("typed");
const hasRuntime: boolean = tags.has("runtime");
const summary: string = Array.from(tags).join(",");
console.log(`tags=${summary}`);
console.log(`runtime=${hasRuntime}`);
const extraTag: string = "runtime";
const tags: Set<string> = new Set<string>(["typed", "web"]);
tags.add(extraTag);
tags.add("typed");
const hasRuntime: boolean = tags.has("runtime");
const summary: string = Array.from(tags).join(",");
console.log(`tags=${summary}`);
console.log(`runtime=${hasRuntime}`);
const extraTag: string = "web";
const tags: Set<string> = new Set<string>(["typed", "web"]);
tags.add(extraTag);
tags.add("typed");
const hasRuntime: boolean = tags.has("runtime");
const summary: string = Array.from(tags).join(",");
console.log(`tags=${summary}`);
console.log(`runtime=${hasRuntime}`);
extraTag ← typed, tags ← [object Set], hasRuntime ← false, summary ← typed,web
1const extraTag→ typed: string = "typed"; //@extraTag="runtime", "web"2const tags→ [object Set]: Set<string> = new Set<string>(["typed", "web"]);34tags.add(extraTagtyped);5tags.add("typed");67const hasRuntime→ false: boolean = tags[object Set].has("runtime");8const summary→ typed,web: string = Array.from(tags[object Set]).join(",");910console.log(`tags=${summarytyped,web}`);11console.log(`runtime=${hasRuntimefalse}`);outputtags=typed,web runtime=false
extraTag ← runtime, tags ← [object Set], hasRuntime ← true, summary ← typed,web,runtime
1const extraTag→ runtime: string = "runtime";2const tags→ [object Set]: Set<string> = new Set<string>(["typed", "web"]);34tags.add(extraTagruntime);5tags.add("typed");67const hasRuntime→ true: boolean = tags[object Set].has("runtime");8const summary→ typed,web,runtime: string = Array.from(tags[object Set]).join(",");910console.log(`tags=${summarytyped,web,runtime}`);11console.log(`runtime=${hasRuntimetrue}`);outputtags=typed,web,runtime runtime=true
extraTag ← web, tags ← [object Set], hasRuntime ← false, summary ← typed,web
1const extraTag→ web: string = "web";2const tags→ [object Set]: Set<string> = new Set<string>(["typed", "web"]);34tags.add(extraTagweb);5tags.add("typed");67const hasRuntime→ false: boolean = tags[object Set].has("runtime");8const summary→ typed,web: string = Array.from(tags[object Set]).join(",");910console.log(`tags=${summarytyped,web}`);11console.log(`runtime=${hasRuntimefalse}`);outputtags=typed,web runtime=false