1
|
'use strict';
|
2
|
|
3
|
module.exports = function union(init) {
|
4
|
if (!Array.isArray(init)) {
|
5
|
throw new TypeError('arr-union expects the first argument to be an array.');
|
6
|
}
|
7
|
|
8
|
var len = arguments.length;
|
9
|
var i = 0;
|
10
|
|
11
|
while (++i < len) {
|
12
|
var arg = arguments[i];
|
13
|
if (!arg) continue;
|
14
|
|
15
|
if (!Array.isArray(arg)) {
|
16
|
arg = [arg];
|
17
|
}
|
18
|
|
19
|
for (var j = 0; j < arg.length; j++) {
|
20
|
var ele = arg[j];
|
21
|
|
22
|
if (init.indexOf(ele) >= 0) {
|
23
|
continue;
|
24
|
}
|
25
|
init.push(ele);
|
26
|
}
|
27
|
}
|
28
|
return init;
|
29
|
};
|