@jp2kk2/

symmetric difference-1

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
function sym() {
  var args = [].slice.call(arguments);
  var final = [];
  var s = 0;
  
  for (i=args.length; i > 0; i --){
   
    for( j=0 ; j < args[0].length; j++){
      //console.log(args);
      console.log(final, final.indexOf(args[0][j]));
      
      if (final.indexOf(args[0][j]) == -1){
      
        final.push(args[0][j]);
      
      } else {
        
        args[0].splice(j,1);
        final.splice(final.indexOf(args[0][j]),1);
        j--;
      }
      
    }
   
    args.shift();
  }

  return final;
}

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