Skip to content

Instantly share code, notes, and snippets.

@samkahchiin
Created March 27, 2016 11:56
Show Gist options
  • Save samkahchiin/eb0d958fe2ed83aebe41 to your computer and use it in GitHub Desktop.
Save samkahchiin/eb0d958fe2ed83aebe41 to your computer and use it in GitHub Desktop.
freecodecamp : sorted union
function unite(arr1, arr2, arr3) {
var combined = arguments[0];
for(var x = 1; x < arguments.length; x++){
for(var i = 0; i < arguments[x].length; i++){
var counter = 0;
for(var j = 0; j < combined.length; j++){
if(arguments[x][i] != combined[j]){
counter++;
}
}
if(counter == combined.length){
combined.push(arguments[x][i]);
}
}
}
return combined;
}
unite([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment