1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var arrayPush = require('./_arrayPush'),
  2. baseFlatten = require('./_baseFlatten'),
  3. copyArray = require('./_copyArray'),
  4. isArray = require('./isArray');
  5. /**
  6. * Creates a new array concatenating `array` with any additional arrays
  7. * and/or values.
  8. *
  9. * @static
  10. * @memberOf _
  11. * @since 4.0.0
  12. * @category Array
  13. * @param {Array} array The array to concatenate.
  14. * @param {...*} [values] The values to concatenate.
  15. * @returns {Array} Returns the new concatenated array.
  16. * @example
  17. *
  18. * var array = [1];
  19. * var other = _.concat(array, 2, [3], [[4]]);
  20. *
  21. * console.log(other);
  22. * // => [1, 2, 3, [4]]
  23. *
  24. * console.log(array);
  25. * // => [1]
  26. */
  27. function concat() {
  28. var length = arguments.length;
  29. if (!length) {
  30. return [];
  31. }
  32. var args = Array(length - 1),
  33. array = arguments[0],
  34. index = length;
  35. while (index--) {
  36. args[index - 1] = arguments[index];
  37. }
  38. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  39. }
  40. module.exports = concat;