Created
August 29, 2015 06:44
-
-
Save ryansukale/67c7cbf6fabbc3a1c452 to your computer and use it in GitHub Desktop.
Array diff
This file contains 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
function getArrayDiff(a, b) { | |
var ret = []; | |
if (!(Array.isArray(a) && Array.isArray(b))) { | |
return ret; | |
} | |
var i; | |
var key; | |
for (i = a.length - 1; i >= 0; i--) { | |
key = a[i]; | |
if (-1 === b.indexOf(key)) { | |
ret.push(key); | |
} | |
} | |
return ret; | |
} |
This file contains 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
_.difference(arr1, arr2); | |
// OR | |
_.without.apply(_, [arr1].concat(arr2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment