1 var arrayPush = require('./_arrayPush'),
2 isFlattenable = require('./_isFlattenable');
5 * The base implementation of `_.flatten` with support for restricting flattening.
8 * @param {Array} array The array to flatten.
9 * @param {number} depth The maximum recursion depth.
10 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
11 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
12 * @param {Array} [result=[]] The initial result value.
13 * @returns {Array} Returns the new flattened array.
15 function baseFlatten(array, depth, predicate, isStrict, result) {
17 length = array.length;
19 predicate || (predicate = isFlattenable);
20 result || (result = []);
22 while (++index < length) {
23 var value = array[index];
24 if (depth > 0 && predicate(value)) {
26 // Recursively flatten arrays (susceptible to call stack limits).
27 baseFlatten(value, depth - 1, predicate, isStrict, result);
29 arrayPush(result, value);
31 } else if (!isStrict) {
32 result[result.length] = value;
38 module.exports = baseFlatten;