Sorted Union - my code not accepted

Tell us what’s happening:
I have checked my code using my own editor and it returns all arrays as it is supposed to yet FCC interface tells me I am not returning the correct values. I have also double checked if the the returned value is an array.

Your code so far


function uniteUnique(arr) {
let newArr=[];
 
 for (let i = 0; i < arr.length; i++) {
     for(let j=0; j<arr[i].length;j++)
     {
         if(newArr.includes(arr[i][j])===false){
             newArr.push(arr[i][j]);
         }
     }    
}
 
 return newArr;
 
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Sorted Union

Link to the challenge:

You are treating the problem as if an array of arrays is being passed to the function yet that is not correct. Atleast two arrays are being passed as arguments. To continue with your approach first put your arguments into an array like
const myNewArr = [...arguments] and in your loop deal with myNewArr and newArr

1 Like

OMG I feel stupid. Copied my code from the editor and forgot to copy the spread operator to the function parameter.

Thanks for your help