Created
March 27, 2016 11:56
-
-
Save samkahchiin/eb0d958fe2ed83aebe41 to your computer and use it in GitHub Desktop.
freecodecamp : sorted union
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 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