File tree Expand file tree Collapse file tree 1 file changed +4
-15
lines changed
Expand file tree Collapse file tree 1 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
564564** Bad:**
565565``` javascript
566566Array .prototype .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));
581569};
582570```
583571
584572** Good:**
585573``` javascript
586574class SuperArray extends Array {
587575 diff (comparisonArray ) {
588- return this .filter (elem => ! comparisonArray .includes (elem));
576+ const hash = new Set (comparisonArray);
577+ return this .filter (elem => ! hash .has (elem));
589578 }
590579}
591580```
You can’t perform that action at this time.
0 commit comments