| 1 | class 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 | |
| 24 | let a = PGroup.empty.add("a"); |
| 25 | let ab = a.add("b"); |
nothing calls this directly
no outgoing calls
no test coverage detected