Hello guys,
I’ve completed the Sorted Union challenge, this is my solution:
function uniteUnique(arr) {
var unique;
var result = [];
for(var i = 0; i < arguments.length; i++){
for(var j = 0; j < arguments[i].length; j++){
// console.log(arguments[i][j]);
result.push(arguments[i][j]);
// console.log(result);
}
}
unique = result.filter(function(elem,index,self){
return index == self.indexOf(elem);
});
return unique;
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
First I tried to solve this issue without any builtin array methods, but I could not come up with any ideas. So I checked google, how to solve this type of issue with array methods.(which array methods to use).
But I’m curious if this challenge can be solved without using methods like filter, reduce and the others. By this I mean, is there a way to compare the indexes inside the result array, and sort out the duplicates?
Thank you!
