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

Class GroupIterator

code/solutions/06_3_iterable_groups.js:31–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31class GroupIterator {
32 #members;
33 #position;
34
35 constructor(members) {
36 this.#members = members;
37 this.#position = 0;
38 }
39
40 next() {
41 if (this.#position >= this.#members.length) {
42 return {done: true};
43 } else {
44 let result = {value: this.#members[this.#position],
45 done: false};
46 this.#position++;
47 return result;
48 }
49 }
50}
51
52for (let value of Group.from(["a", "b", "c"])) {
53 console.log(value);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected