Tell us what’s happening:
Hello,
-
I can’t chain .unshift(arr) to the end of args and was wondering why. The .concat() method seems to work fine so I’m a little confused as to why .unshift() wouldn’t work as well.
-
I wanted to see what happened by changing the value in one of the 2d arrays:
uniteUnique([1, 3, 2], [1, [5]], [2, [3]]);
//returns [1, 3, 2, [5], [3]] which doesn’t pass the requirement to return only unique values
Removing the brackets from the numbers seem to allow the filter to iterate over the value which leads me to suspect the filter() isn’t even iterating over the 2d arrays.
Can someone tell me what is going on? Do I need to further flatten the arrays? Or is this simply a bug of filter?
Also, all the code hint solutions behave the same way.
Your code so far
function uniteUnique(arr) {
var args = Object.values(arguments);
args = args.reduce((accu, curr) => {
return accu.concat(curr);
}).filter(x => {
if (!arr.includes(x)){
return x
}
});
return arr.concat(args)
}
uniteUnique([1, 3, 2], [1, [5]], [2, [3]]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sorted-union/