index.js 527 B

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