-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortedUnion.js
More file actions
19 lines (17 loc) · 876 Bytes
/
sortedUnion.js
File metadata and controls
19 lines (17 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays.
In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.
The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order. */
function uniteUnique(arr) {
var uniqueArrCombine = [];
for (var i = 0; i < arguments.length; i++) {
var arrayArguments = arguments[i];
for (var j = 0; j < arrayArguments.length; j++) {
var indexValue = arrayArguments[j];
if (uniqueArrCombine.indexOf(indexValue) < 0) {
uniqueArrCombine.push(indexValue);
}
}
}
return uniqueArrCombine;
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);