(input, shallow, strict, startIndex)
| 488 | |
| 489 | // Internal implementation of a recursive `flatten` function. |
| 490 | var flatten = function(input, shallow, strict, startIndex) { |
| 491 | var output = [], idx = 0; |
| 492 | for (var i = startIndex || 0, length = getLength(input); i < length; i++) { |
| 493 | var value = input[i]; |
| 494 | if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) { |
| 495 | //flatten current level of array or arguments object |
| 496 | if (!shallow) value = flatten(value, shallow, strict); |
| 497 | var j = 0, len = value.length; |
| 498 | output.length += len; |
| 499 | while (j < len) { |
| 500 | output[idx++] = value[j++]; |
| 501 | } |
| 502 | } else if (!strict) { |
| 503 | output[idx++] = value; |
| 504 | } |
| 505 | } |
| 506 | return output; |
| 507 | }; |
| 508 | |
| 509 | // Flatten out an array, either recursively (by default), or just one level. |
| 510 | _.flatten = function(array, shallow) { |
no test coverage detected