Created
March 6, 2009 16:57
-
-
Save ynniv/74973 to your computer and use it in GitHub Desktop.
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 intersection(a, b) { | |
var shorter = a, longer = b, hash = {}; | |
if (a.length > b.length) { shorter = b; longer = a; } | |
for (var i in shorter) { var o = shorter[i]; hash[o] = 1; } | |
var collisions = []; | |
for (var i in longer) { | |
var o = longer[i]; | |
if (hash[o] == 1) collisions.push(o); | |
} | |
return collisions; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment