* The base implementation of `_.flatten` with support for restricting flattening. * * @private * @param {Array} array The array to flatten. * @param {number} depth The maximum recursion depth. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
(array, depth, predicate, isStrict, result)
| 2978 | * @returns {Array} Returns the new flattened array. |
| 2979 | */ |
| 2980 | function baseFlatten(array, depth, predicate, isStrict, result) { |
| 2981 | var index = -1, |
| 2982 | length = array.length; |
| 2983 | |
| 2984 | predicate || (predicate = isFlattenable); |
| 2985 | result || (result = []); |
| 2986 | |
| 2987 | while (++index < length) { |
| 2988 | var value = array[index]; |
| 2989 | if (depth > 0 && predicate(value)) { |
| 2990 | if (depth > 1) { |
| 2991 | // Recursively flatten arrays (susceptible to call stack limits). |
| 2992 | baseFlatten(value, depth - 1, predicate, isStrict, result); |
| 2993 | } else { |
| 2994 | arrayPush(result, value); |
| 2995 | } |
| 2996 | } else if (!isStrict) { |
| 2997 | result[result.length] = value; |
| 2998 | } |
| 2999 | } |
| 3000 | return result; |
| 3001 | } |
| 3002 | |
| 3003 | /** |
| 3004 | * The base implementation of `baseForOwn` which iterates over `object` |
no test coverage detected