Created
July 11, 2012 10:55
-
-
Save jaz303/3089647 to your computer and use it in GitHub Desktop.
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
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