main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1005 bytes
|
Rev | Line | |
---|
[d565449] | 1 | import arrayPush from './_arrayPush.js';
|
---|
| 2 | import baseFlatten from './_baseFlatten.js';
|
---|
| 3 | import copyArray from './_copyArray.js';
|
---|
| 4 | import isArray from './isArray.js';
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * Creates a new array concatenating `array` with any additional arrays
|
---|
| 8 | * and/or values.
|
---|
| 9 | *
|
---|
| 10 | * @static
|
---|
| 11 | * @memberOf _
|
---|
| 12 | * @since 4.0.0
|
---|
| 13 | * @category Array
|
---|
| 14 | * @param {Array} array The array to concatenate.
|
---|
| 15 | * @param {...*} [values] The values to concatenate.
|
---|
| 16 | * @returns {Array} Returns the new concatenated array.
|
---|
| 17 | * @example
|
---|
| 18 | *
|
---|
| 19 | * var array = [1];
|
---|
| 20 | * var other = _.concat(array, 2, [3], [[4]]);
|
---|
| 21 | *
|
---|
| 22 | * console.log(other);
|
---|
| 23 | * // => [1, 2, 3, [4]]
|
---|
| 24 | *
|
---|
| 25 | * console.log(array);
|
---|
| 26 | * // => [1]
|
---|
| 27 | */
|
---|
| 28 | function concat() {
|
---|
| 29 | var length = arguments.length;
|
---|
| 30 | if (!length) {
|
---|
| 31 | return [];
|
---|
| 32 | }
|
---|
| 33 | var args = Array(length - 1),
|
---|
| 34 | array = arguments[0],
|
---|
| 35 | index = length;
|
---|
| 36 |
|
---|
| 37 | while (index--) {
|
---|
| 38 | args[index - 1] = arguments[index];
|
---|
| 39 | }
|
---|
| 40 | return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | export default concat;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.