index.js 550 B

123456789101112131415161718192021222324252627282930
  1. /*!
  2. * arr-union <https://github.com/jonschlinkert/arr-union>
  3. *
  4. * Copyright (c) 2014-2015, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. 'use strict';
  8. module.exports = function union(arr) {
  9. var len = arguments.length;
  10. var res = [], i = 0;
  11. while (len--) {
  12. var arg = arrayify(arguments[i++]);
  13. for (var j = 0; j < arg.length; j++) {
  14. var ele = arg[j];
  15. if (res.indexOf(ele) === -1) {
  16. res.push(ele);
  17. }
  18. }
  19. }
  20. return res;
  21. };
  22. function arrayify(val) {
  23. return Array.isArray(val) ? val : [val];
  24. }