Skip to content

Instantly share code, notes, and snippets.

@pukie
Last active November 23, 2016 12:37
Show Gist options
  • Select an option

  • Save pukie/4f409b91eab8cd4a0493e261779128e7 to your computer and use it in GitHub Desktop.

Select an option

Save pukie/4f409b91eab8cd4a0493e261779128e7 to your computer and use it in GitHub Desktop.
var tablica_1 = [1,2,3,4,6],
tablica_2 = [3,1,5,6],
tablica_3 = [3,1,2,3,6],
tablica_4 = [3,5,6];
function findCommonElements (){
var argumentsArray = arguments;
var result = arguments[0].filter(function(value) {
var isEqual = true;
for(var i = 1 ; i < argumentsArray.length ; i++){
if(argumentsArray[i].indexOf(value) < 0) isEqual = false;
}
return isEqual;
});
console.log(result);
}
//test
findCommonElements (tablica_1,tablica_2,tablica_3);
findCommonElements (tablica_1,tablica_2,tablica_3,tablica_4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment