You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1005 B
44 lines
1005 B
2 years ago
|
import arrayPush from './_arrayPush.js';
|
||
|
import baseFlatten from './_baseFlatten.js';
|
||
|
import copyArray from './_copyArray.js';
|
||
|
import isArray from './isArray.js';
|
||
|
|
||
|
/**
|
||
|
* Creates a new array concatenating `array` with any additional arrays
|
||
|
* and/or values.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @since 4.0.0
|
||
|
* @category Array
|
||
|
* @param {Array} array The array to concatenate.
|
||
|
* @param {...*} [values] The values to concatenate.
|
||
|
* @returns {Array} Returns the new concatenated array.
|
||
|
* @example
|
||
|
*
|
||
|
* var array = [1];
|
||
|
* var other = _.concat(array, 2, [3], [[4]]);
|
||
|
*
|
||
|
* console.log(other);
|
||
|
* // => [1, 2, 3, [4]]
|
||
|
*
|
||
|
* console.log(array);
|
||
|
* // => [1]
|
||
|
*/
|
||
|
function concat() {
|
||
|
var length = arguments.length;
|
||
|
if (!length) {
|
||
|
return [];
|
||
|
}
|
||
|
var args = Array(length - 1),
|
||
|
array = arguments[0],
|
||
|
index = length;
|
||
|
|
||
|
while (index--) {
|
||
|
args[index - 1] = arguments[index];
|
||
|
}
|
||
|
return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
|
||
|
}
|
||
|
|
||
|
export default concat;
|