Skip to content

Instantly share code, notes, and snippets.

@jaz303
Created July 11, 2012 10:55
Show Gist options
  • Save jaz303/3089647 to your computer and use it in GitHub Desktop.
Save jaz303/3089647 to your computer and use it in GitHub Desktop.
function array_diff(foo, bar) {
var d=[], i=0, j=0;
foo.sort();
bar.sort();
while (i < foo.length && j < bar.length) {
var l = foo[i], r = bar[j];
if (l < r) {
d.push(l);
i++;
} else if (l == r) {
i++;
j++;
} else {
d.push(r);
j++;
}
}
while (i < foo.length) d.push(foo[i++]);
while (j < bar.length) d.push(bar[j++]);
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment