mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Simplify baseFlatten and always provide a fromIndex.
This commit is contained in:
@@ -2144,13 +2144,13 @@
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to flatten.
|
||||
* @param {boolean} [isDeep] Specify a deep flatten.
|
||||
* @param {boolean} [isStrict] Restrict flattening to arrays and `arguments` objects.
|
||||
* @param {number} [fromIndex=0] The index to start from.
|
||||
* @param {boolean} isDeep Specify a deep flatten.
|
||||
* @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
|
||||
* @param {number} fromIndex The index to start from.
|
||||
* @returns {Array} Returns the new flattened array.
|
||||
*/
|
||||
function baseFlatten(array, isDeep, isStrict, fromIndex) {
|
||||
var index = fromIndex == null ? -1 : (fromIndex - 1),
|
||||
var index = fromIndex - 1,
|
||||
length = array.length,
|
||||
resIndex = -1,
|
||||
result = [];
|
||||
@@ -2161,7 +2161,7 @@
|
||||
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
|
||||
if (isDeep) {
|
||||
// Recursively flatten arrays (susceptible to call stack limits).
|
||||
value = baseFlatten(value, isDeep, isStrict);
|
||||
value = baseFlatten(value, isDeep, isStrict, 0);
|
||||
}
|
||||
var valIndex = -1,
|
||||
valLength = value.length;
|
||||
@@ -4666,7 +4666,7 @@
|
||||
if (guard && isIterateeCall(array, isDeep, guard)) {
|
||||
isDeep = false;
|
||||
}
|
||||
return length ? baseFlatten(array, isDeep) : [];
|
||||
return length ? baseFlatten(array, isDeep, false, 0) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4684,7 +4684,7 @@
|
||||
*/
|
||||
function flattenDeep(array) {
|
||||
var length = array ? array.length : 0;
|
||||
return length ? baseFlatten(array, true) : [];
|
||||
return length ? baseFlatten(array, true, false, 0) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5344,7 +5344,7 @@
|
||||
* // => [1, 2, 4]
|
||||
*/
|
||||
function union() {
|
||||
return baseUniq(baseFlatten(arguments, false, true));
|
||||
return baseUniq(baseFlatten(arguments, false, true, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user