union.js 412 B

123456789101112131415161718192021
  1. var uniq = require('./uniq')
  2. var toArray = require('./toArray')
  3. /**
  4. * 将多个数的值返回唯一的并集数组
  5. *
  6. * @param {...Array} 数组
  7. * @return {Array}
  8. */
  9. function union () {
  10. var args = arguments
  11. var result = []
  12. var index = 0
  13. var len = args.length
  14. for (; index < len; index++) {
  15. result = result.concat(toArray(args[index]))
  16. }
  17. return uniq(result)
  18. }
  19. module.exports = union