MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / PGroup

Class PGroup

code/solutions/07_3_persistent_group.js:1–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class PGroup {
2 #members;
3 constructor(members) {
4 this.#members = members;
5 }
6
7 add(value) {
8 if (this.has(value)) return this;
9 return new PGroup(this.#members.concat([value]));
10 }
11
12 delete(value) {
13 if (!this.has(value)) return this;
14 return new PGroup(this.#members.filter(m => m !== value));
15 }
16
17 has(value) {
18 return this.#members.includes(value);
19 }
20
21 static empty = new PGroup([]);
22}
23
24let a = PGroup.empty.add("a");
25let ab = a.add("b");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected