@anonymous/

FearfulUnconsciousWebsites

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
function sym(args) {
  var arr, i, 
      numCount={},
      singles=[],
      temp=[],
      result=[];

      // 2 sets: merge first 2 arguments into 1 array
   if(arguments.length<=2){
  arr = Array.from(arguments).reduce((a, b) => a.concat(b),[]);
  
  // check nums that occur only 1x
  numCount = arr.reduce(function(set, num){
    if (num in set) {
       set[num]++;
    } else {
        set[num]=1;
    }
    return set;
    }, {});
  
  //store all single occurences in new array "singles"
  for (i in numCount){
      if(numCount[i]===1){
        singles.push(i);
        temp = singles.map(Number);
      }
    }
  }
  // 3+ sets
  if(arguments.length>2){
   temp = Array.prototype.slice.call(arguments, 0, 2);
   arr = Array.from(temp).reduce((a, b) => a.concat(b),[]);
  }
  return arr;
}

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