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

Class Group

code/solutions/06_2_groups.js:1–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Group {
2 #members = [];
3
4 add(value) {
5 if (!this.has(value)) {
6 this.#members.push(value);
7 }
8 }
9
10 delete(value) {
11 this.#members = this.#members.filter(v => v !== value);
12 }
13
14 has(value) {
15 return this.#members.includes(value);
16 }
17
18 static from(collection) {
19 let group = new Group;
20 for (let value of collection) {
21 group.add(value);
22 }
23 return group;
24 }
25}
26
27let group = Group.from([10, 20]);
28console.log(group.has(10));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected