1 var isArguments = require('../lang/isArguments'),
2 isArray = require('../lang/isArray'),
3 isLength = require('./isLength'),
4 isObjectLike = require('./isObjectLike');
7 * The base implementation of `_.flatten` with added support for restricting
8 * flattening and specifying the start index.
11 * @param {Array} array The array to flatten.
12 * @param {boolean} isDeep Specify a deep flatten.
13 * @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
14 * @returns {Array} Returns the new flattened array.
16 function baseFlatten(array, isDeep, isStrict) {
18 length = array.length,
22 while (++index < length) {
23 var value = array[index];
25 if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
27 // Recursively flatten arrays (susceptible to call stack limits).
28 value = baseFlatten(value, isDeep, isStrict);
31 valLength = value.length;
33 result.length += valLength;
34 while (++valIndex < valLength) {
35 result[++resIndex] = value[valIndex];
37 } else if (!isStrict) {
38 result[++resIndex] = value;
44 module.exports = baseFlatten;