Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,28 +564,17 @@ would be much better to just use ES2015/ES6 classes and simply extend the `Array
**Bad:**
```javascript
Array.prototype.diff = function diff(comparisonArray) {
const values = [];
const hash = {};

for (const i of comparisonArray) {
hash[i] = true;
}

for (const i of this) {
if (!hash[i]) {
values.push(i);
}
}

return values;
const hash = new Set(comparisonArray);
return this.filter(elem => !hash.has(elem));
};
```

**Good:**
```javascript
class SuperArray extends Array {
diff(comparisonArray) {
return this.filter(elem => !comparisonArray.includes(elem));
const hash = new Set(comparisonArray);
return this.filter(elem => !hash.has(elem));
}
}
```
Expand Down