@rscales02/

fcc Symmetric difference

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function sym(args) {
  var argArray = Array.prototype.slice.call(arguments),
      temp = [];
  
  if (argArray.length == 1) {
    argArray = argArray.reduce(function(a, b) {
      return a.concat(b);
    }, []);
  } 
  
  for (var i = 0; i < argArray[0].length; i++){
    if (argArray[1].indexOf(argArray[0][i]) !== -1) {
      temp.push(argArray[0][i]);
      argArray[0].splice(i, 1);
      i--;
    }
  }
  console.log(temp);
  for (var j = 0; j < argArray[1].length; j++) {
    if (temp.indexOf(argArray[1][j]) === -1) {
      argArray[0].push(argArray[1][j]);
    }  
  }
  argArray.splice(1, 1);
  argArray[0].sort();
  if (argArray.length == 1){
  console.log(argArray[0]);
    return argArray[0];
  } else {
    
    sym(argArray);
  }
  argArray[0] = argArray[0].filter(function(item, pos) {
    return argArray[0].indexOf(item) == pos;
})
  return argArray[0];
  
}

sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]);
Native Browser JavaScript