Skip to content

Instantly share code, notes, and snippets.

@ryansukale
Created August 29, 2015 06:44
Show Gist options
  • Save ryansukale/67c7cbf6fabbc3a1c452 to your computer and use it in GitHub Desktop.
Save ryansukale/67c7cbf6fabbc3a1c452 to your computer and use it in GitHub Desktop.
Array diff
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;
}
_.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