Skip to content

Instantly share code, notes, and snippets.

@ynniv
Created March 6, 2009 16:57
Show Gist options
  • Save ynniv/74973 to your computer and use it in GitHub Desktop.
Save ynniv/74973 to your computer and use it in GitHub Desktop.
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