Intermediate Algorithm Scripting1: Sorted Union

Tell us what’s happening:
Can someone tell me why my array doesn’t concat?

Your code so far

function uniteUnique(arr) {
var i=0;
var b=arguments.length;
var a=[];
 for(let i=0;i<b;i++){
for(let i=0;i<a.length;i++){
  for(let j=1;j<a.length;j++){
    if(a[i]===a[j] && i!==j){
return a;

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/83.0.4103.97 Safari/537.36.

Challenge: Sorted Union

Link to the challenge:

It does concat, only every loop iteration is overwriting the result, so what you’ll get in the end is first and last arrays from arguments concatenated.

@jenovs can you tell me why does this overwrite. Actually I am new to coding and don’t understand this.