Simplify baseFlatten and always provide a fromIndex.

This commit is contained in:
jdalton
2015-03-01 01:22:00 -08:00
parent ec1be41b62
commit 3aa40d4df6

View File

@@ -2144,13 +2144,13 @@
* *
* @private * @private
* @param {Array} array The array to flatten. * @param {Array} array The array to flatten.
* @param {boolean} [isDeep] Specify a deep flatten. * @param {boolean} isDeep Specify a deep flatten.
* @param {boolean} [isStrict] Restrict flattening to arrays and `arguments` objects. * @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
* @param {number} [fromIndex=0] The index to start from. * @param {number} fromIndex The index to start from.
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
*/ */
function baseFlatten(array, isDeep, isStrict, fromIndex) { function baseFlatten(array, isDeep, isStrict, fromIndex) {
var index = fromIndex == null ? -1 : (fromIndex - 1), var index = fromIndex - 1,
length = array.length, length = array.length,
resIndex = -1, resIndex = -1,
result = []; result = [];
@@ -2161,7 +2161,7 @@
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) { if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
if (isDeep) { if (isDeep) {
// Recursively flatten arrays (susceptible to call stack limits). // Recursively flatten arrays (susceptible to call stack limits).
value = baseFlatten(value, isDeep, isStrict); value = baseFlatten(value, isDeep, isStrict, 0);
} }
var valIndex = -1, var valIndex = -1,
valLength = value.length; valLength = value.length;
@@ -4666,7 +4666,7 @@
if (guard && isIterateeCall(array, isDeep, guard)) { if (guard && isIterateeCall(array, isDeep, guard)) {
isDeep = false; isDeep = false;
} }
return length ? baseFlatten(array, isDeep) : []; return length ? baseFlatten(array, isDeep, false, 0) : [];
} }
/** /**
@@ -4684,7 +4684,7 @@
*/ */
function flattenDeep(array) { function flattenDeep(array) {
var length = array ? array.length : 0; 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] * // => [1, 2, 4]
*/ */
function union() { function union() {
return baseUniq(baseFlatten(arguments, false, true)); return baseUniq(baseFlatten(arguments, false, true, 0));
} }
/** /**