Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays. In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array. The unique numbers should be sorted by their original order, but the final …
function uniteUnique(arr) {
var args = [];
//loop over the arguments provided and then loop over each array
//within the arguments, check if the value is already in the new
//array, if it's not, add it in.
for(var i = 0; i < arguments.length; i++){
for(var j = 0; j<arguments[i].length; j++){
if(args.indexOf(arguments[i][j]) == -1){
args.push(arguments[i][j]);
}
}//end for j
}//end for i
return args;
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment