Tell us what’s happening:
Hello. So for this challenge i create an array with all the values of all the arguments and then i create an empty one. Using a for loop i try to push in the empty array all the values that are not already in my empty array. As you can see, some values are ‘undefined’. Why is this happening, i dont understand.
Thanks, in Advanced!
Your code so far
function uniteUnique(arr,...args) {
let newArr = [...arr];
for(let i=0;i<args.length;i++){
newArr=newArr.concat(args[i]);
}
let arr2 = [];
for(let i=0;i<newArr.length;i++){
if(!arr2.includes(newArr[i])){
arr2.push(arr[i]);
}
}
console.log(arr2);
return arr;
}
//uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
//uniteUnique([1, 2, 3], [5, 2, 1]);
uniteUnique([1, 2, 3,3,5,6], [5, 2, 1, 4], [2, 1], [6, 7, 8]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36
.
Challenge: Sorted Union
Link to the challenge: