-
Notifications
You must be signed in to change notification settings - Fork 0
/
sym2.js
74 lines (45 loc) · 1.2 KB
/
sym2.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function sym(args) {
function symOfTwo(a, b) {
let temp = [];
// delete repeating numbers in each list
function removeDuplicates (input) {
let result = input.filter(function(item, pos) {
return input.indexOf(item) == pos;
});
return result
};
a = removeDuplicates(a);
b = removeDuplicates(b);
// merge arrays
let merged = a.concat(b);
//count instances of each number with counter array
let counter = [];
for (let i = 0; i < merged.length; i++) {
if (counter[merged[i]] == true) {
counter[merged[i]] = false;
}
else {
counter[merged[i]] = true;
}
}
// return a print of the counter array
merged = [];
for (let i = 0; i < counter.length; i++) {
if (counter[i] == true) {
merged.push(i)
}
}
return merged;
}
// find the sym of the first two arrays
let a = arguments[0];
let b = arguments[1];
let result = symOfTwo(a, b)
for (let i = 2; i < arguments.length; i++) {
// then repeat for all the other arrays, comparing i + 1 and the previous result
result = symOfTwo(result, arguments[i])
}
console.log(result);
return result;
}
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])