# Solution explanation - Sorted Union algorithm \[Spoiler\]

**URL:** <https://forum.freecodecamp.org/t/solution-explanation-sorted-union-algorithm-spoiler/24686>\
**Category:** General\
**Created:** [August 1, 2016, 11:40pm UTC](https://forum.freecodecamp.org/t/solution-explanation-sorted-union-algorithm-spoiler/24686 "2016-08-01T23:40:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pilgrim011](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pilgrim011/32/16352_2.png) [@pilgrim011](https://forum.freecodecamp.org/u/pilgrim011)\
**Post date:** [August 1, 2016, 11:40pm UTC](https://forum.freecodecamp.org/t/solution-explanation-sorted-union-algorithm-spoiler/24686/1 "2016-08-01T23:40:40Z")

</div>

So, this is the solution that was partially copy/pasted from the web:

> function uniteUnique(arr) {  
> var sorted =;  
> var makeArray = Array.from(arguments);
> 
> ```
> for (i=0; i<makeArray.length; i++) { 
> for (x=0; x<makeArray[i].length; x++) {
> sorted.push(makeArray[i][x]);    
> }
> }
> console.log(sorted);
> 
> ```
> 
> var final = sorted.reduce(function(a,b){  
> if (a.indexOf(b)\<0){  
> a.push(b);
> 
> ```
> }
> return a;
> },[]);
> 
> ```
> 
> return final;  
> }

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

I don’t get this, despite of reading about it on MDN etc. I’m bad with functions… These are the problematic things: if reduce() function takes 4 args (previousValue, currentValue, currentIndex, array), which two of these four are a and b? I thought they are previous and current value, but if so, how can we compare two array elements with indexOf and push one array element (b) into another array element (a), and not into array? Also, why do I get the desired result only when I \> return a; ?  
Finally, what is \> in the function?  
So, you now know that I don’t get this solution at all…😊😢

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [August 2, 2016, 12:55am UTC](https://forum.freecodecamp.org/t/solution-explanation-sorted-union-algorithm-spoiler/24686/2 "2016-08-02T00:55:30Z")

</div>

Can’t type a lot right now. Check out this video and see if it answers some questions: [https://youtu.be/Wl98eZpkp-c](https://youtu.be/Wl98eZpkp-c)

---

<div class="post-metadata">

**Author:** ![pilgrim011](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pilgrim011/32/16352_2.png) [@pilgrim011](https://forum.freecodecamp.org/u/pilgrim011)\
**Post date:** [August 2, 2016, 8:24am UTC](https://forum.freecodecamp.org/t/solution-explanation-sorted-union-algorithm-spoiler/24686/3 "2016-08-02T08:24:34Z")

</div>

Oh yes, this guy knows how to explain! Thank you!

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 4:40am UTC](https://forum.freecodecamp.org/t/solution-explanation-sorted-union-algorithm-spoiler/24686/4 "2021-01-16T04:40:54Z")

</div>

Closed on January 16, 2021, 4:40am UTC


