# Sorted Union- JS Intermediate Algorithms

Tell us what’s happening:
I use VS Code to write and test the code. My solution code passes all of the tests when I run them via VS Code. But fails all of the tests when entered and submitted on the FCC code editor. How could this be?

`````` **Your code so far**
``````
``````
function uniteUnique(arr) {
const numSet = new Set([...arr].flat(1));
const numbers = [];
numSet.forEach((value) => numbers.push(value));
return numbers;
}

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/89.0.4389.90 Safari/537.36 Edg/89.0.774.57`.

Challenge: Sorted Union

This isn’t possible, not with the code you’ve posted – it can’t pass any of the tests.

You are taking the first array passed to the function, removing any duplicates, and returning that: this it the output for your function for each of the tests:

``````uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1])
// [1, 3, 2]
uniteUnique([1, 2, 3], [5, 2, 1])
// [1, 2, 3]
uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8])
// [1, 2, 3]
``````

What you’ve written is the same as:

``````function uniteUnique(arr) {
const numSet = new Set(arr);
return Array.from(numSet);
}
``````

And as there are no duplicates in the first array in any of the tests, its the same as:

``````function uniteUnique(arr) {
return arr;
}
``````

The function can take any number of arrays as arguments: at the minute, in the skeleton of the function you get given, `arr` is only referring to the first array that gets passed in.

Yes I see I missed putting the spread in the parameter.
Should have been : function uniteUnique(…arr)

My problem was that I failed to spot that I did not cut and paste my solution function header until about half an hour later. With the rest
…arr it works fine. Thanks for the help.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.