Created
July 31, 2018 07:34
-
-
Save danielt69/3cca1ad406230e0350d82d26a848b2ac to your computer and use it in GitHub Desktop.
Difference Between 2 JavaScript Arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.prototype.diff = function (a) { | |
| return this.filter(function (i) { | |
| return a.indexOf(i) === -1; | |
| }); | |
| }; | |
| // usage: | |
| [1, 2, 3, 4, 5, 6].diff([2, 4, 6]); | |
| // => [1, 3, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment