-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortedUnion.js
More file actions
36 lines (20 loc) · 766 Bytes
/
SortedUnion.js
File metadata and controls
36 lines (20 loc) · 766 Bytes
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
function uniteUnique(arr) {
var uniqueValuesArray = [];
var argumentsArray = Array.prototype.slice.call(arguments);
;
//loop through arrays
argumentsArray.forEach(function (arrayOfValues) {
arrayOfValues.forEach(function (inputValue) {
var addValue = true;
uniqueValuesArray.every(function (outputValue) {
if (outputValue === inputValue) {
addValue = false;
return false;
} else return true;
});
if (addValue === true) uniqueValuesArray.push(inputValue);
});
});
return uniqueValuesArray;
}
console.log(uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]));