MCPcopy
hub / github.com/lodash/lodash / baseFlatten

Function baseFlatten

lodash.js:2980–3001  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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`

Callers 9

baseXorFunction · 0.85
concatFunction · 0.85
lodash.jsFile · 0.85
flattenFunction · 0.85
flattenDeepFunction · 0.85
flattenDepthFunction · 0.85
flatMapFunction · 0.85
flatMapDeepFunction · 0.85
flatMapDepthFunction · 0.85

Calls 2

arrayPushFunction · 0.85
predicateFunction · 0.50

Tested by

no test coverage detected