Skip to content

Instantly share code, notes, and snippets.

@magicento
Forked from lovasoa/README.md
Last active August 29, 2015 14:23
Show Gist options
  • Save magicento/2e7b7884e2f5eade13e2 to your computer and use it in GitHub Desktop.
Save magicento/2e7b7884e2f5eade13e2 to your computer and use it in GitHub Desktop.
function array_intersect() {
var sorted = Array.prototype.slice.call(arguments).sort(function(i,j){return i.length>j.length;});
var shortest = sorted[0];
return shortest.filter(function(elem){
for (var i=sorted.length-1; i>0; i--){
if(sorted[i].indexOf(elem)===-1){return false;}
}
return true;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment