Created
March 22, 2018 20:40
-
-
Save nickihastings/50d1478649c194d3729e6c416d0589c9 to your computer and use it in GitHub Desktop.
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 …
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 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