Sorted Union - freeCodeCamp using Modern JavaScript #10

Did someone say unique values? It't time for Set! This is an exercise where ES6 can really shine, Set is made to store unique values, and that's exactly what we're asked to do here. Let's take it step-by-step.

We're given an arbitrary number of arrays as input, so let's use a rest parameter to collect them all into a single arguments array that we can work with.

constuniteUnique=(...arrays)=>{// ...};

We need to get the values out of each array that was passing into our function, so now that we've collected them all we need to spread them out again. We will also concatenate them to get a single array containing all the values we are interested in.

Array.prototype.concat(...arrays)

In the next step we'll use our Set trick. By calling new Set() on an array we easily and declaratively eliminate duplicates.

Last step is to turn the Set back into an array that freeCodeCamp expects as output. We can use Array.from to get the solution.