marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Ch. 6 – Groups exercise solution could use "has" method in "add" method #379

Closed mikegowen closed 6 years ago

mikegowen commented 6 years ago

Could you use has method in the add method?

add(value) {
    if (!this.has(value)) {
      this.members.push(value);
    }
  }

vs

add(value) {
    if (!this.members.includes(value)) {
      this.members.push(value);
    }
  }

It's possible that you deliberated wanted those two methods untied from each other. If so, ignore.

marijnh commented 6 years ago

That's a good idea. See attached patch.