Review my Symmetric Difference Code

Review my Symmetric Difference Code
0

#1

I have already been to code review gitter.im room for FCC.

After looking at the official basic solution (which half the size of my code) I want your to review my code. Also tell me whether I approached it right or not.

  1. Find Union of Previous and Current Array
  2. Find Intersection of Previous and Current Array
  3. A Δ B = (AUB) - (A∩B).

In exchange of solution, 2-3 times two level deep for loops are used (because, for some reason I forget indexOf).

// Find symmetric values across sets of data delta 
function uniteUnique(arr) {
  var flatten = [],temp = [],final=[];
  for(var i=0;i<arguments.length;i++){
    flatten.push(arguments[i]);
  }

  flatten = flatten.reduce(function(a,b){    
    return a.concat(b);
  },[]);

  duplicate:for(var i=0,j=flatten.length;i<j;i++){
      for(var x=0,y=final.length;x<y;x++){
          if(flatten[i] == final[x]){
              continue duplicate;
          }
        }
        final[final.length] = flatten[i];
  }
  return final;
}

var findUnion = function(a,b){
   return [a,b].reduce(function(a,b){
        return a.concat(b);
    })
}

var findI = function(a,b){
  var intersected = [];
  [a,b].reduce(function(a,b){
    for(var i=0,endI=a.length; i<endI; i++){
      for(var j=0,endJ=b.length; j<endJ; j++){
        if(a[i] == b[j]){
          intersected.push(a[i]);
        }
      }
    }
  })
  return intersected;
}

function sym(args) {
  var tampered = [],symmetric=[],final=[];
  for(var x=0,xEnd=arguments.length; x<xEnd;x++){
      tampered.push(arguments[x]);
  }

  var final = tampered.reduce(function(a,b){
      var union = findUnion(a,b);
      var intersection = findI(a,b);
      var symm = [];

      o:for(var i=0,endI=union.length; i<endI; i++){
        for(var j=0,endJ=intersection.length; j<endJ; j++){
          if(union[i] === intersection[j]){
            continue o;
          }
        }
        symm.push(union[i]);
      }
      return symm;
  })
  return uniteUnique(final);
}

sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]);

#2

Where’s the code? I don’t see a link anywhere to it.


#3

Just added the code.


#5

It’s called label that is used with break/continue statements.
Read more here at mdn.


#7

I wanted to know whether it’s relevant to use Go to type statements in this life time.


#10

Thanks for thoroughly reviewing my code. I agree with you in the labelled continue. In order to read them you actually to debug the code.
I am happy that some of my code is above average. Your code is what 5% of my code and I hope I will understand it one day.

I would like your advice on getting out of loop and nested loops hell.