If there's any problem with my iterator class I'd love to know.
class Group {
constructor(arr = []){
this.array = arr;
}
add(number) {
this.array.push(number);
}
delete(number){
this.array = this.array.filter(n => n != number);
}
has(number){
return this.array.includes(number);
}
static from(array){
return new this(array);
}
}
class GroupIterator{
constrctor(group){
this.x = 0;
this.group = group;
}
next() {
if (this.x == this.group.array.length) return {done: true};
var val = this.x
this.x++;
return {val, done: false};
}
The problem is with the following call:
for(let value of Group.from(["a", "b", "c"])) {
console.log(value);
}
// → a
// → b
// → c