Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14e83d5

Browse files
committed
use functional Array methods
Also exclude hidden type coercion from array elements comparing.
1 parent 7035841 commit 14e83d5

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,7 @@ Array.prototype.diff = function(comparisonArray) {
624624
```javascript
625625
class SuperArray extends Array {
626626
diff(comparisonArray) {
627-
var values = [];
628-
var hash = {};
629-
630-
for (var i of comparisonArray) {
631-
hash[i] = true;
632-
}
633-
634-
for (var i of this) {
635-
if (!hash[i]) {
636-
values.push(i);
637-
}
638-
}
639-
640-
return values;
627+
return this.filter(elem => !comparisonArray.includes(elem));
641628
}
642629
}
643630
```

0 commit comments

Comments
 (0)