File tree
Expand file treeCollapse file tree1 file changed
+4
-15
lines changed Expand file treeCollapse file tree1 file changed
+4
-15
lines changed Original file line number | Diff line number | Diff line change |
---|
@@ -564,28 +564,17 @@ would be much better to just use ES2015/ES6 classes and simply extend the `Array
|
564 | 564 | **Bad:**
|
565 | 565 | ```javascript
|
566 | 566 | Array..diff = function diff(comparisonArray) {
|
567 |
| -const values = []; |
568 |
| -const hash = {}; |
569 |
| - |
570 |
| -for (const i of comparisonArray) { |
571 |
| -hash[i] = true; |
572 |
| -} |
573 |
| - |
574 |
| -for (const i of this) { |
575 |
| -if (!hash[i]) { |
576 |
| -values.push(i); |
577 |
| -} |
578 |
| -} |
579 |
| - |
580 |
| -return values; |
| 567 | +const hash = new Set(comparisonArray); |
| 568 | +return this.filter(elem => !hash.has(elem)); |
581 | 569 | };
|
582 | 570 | ```
|
583 | 571 |
|
584 | 572 | **Good:**
|
585 | 573 | ```javascript
|
586 | 574 | class SuperArray extends Array {
|
587 | 575 | diff(comparisonArray) {
|
588 |
| -return this.filter(elem => !comparisonArray.includes(elem)); |
| 576 | +const hash = new Set(comparisonArray); |
| 577 | +return this.filter(elem => !hash.has(elem)); |
589 | 578 | }
|
590 | 579 | }
|
591 | 580 | ```
|
|
You can’t perform that action at this time.
0 commit comments