lodash: Cleanup flatten avoiding the use of an extraneous empty array. [jddalton]

Former-commit-id: 6a1eebceb77dd59d34659a295c4a7a2dce92e8a9
This commit is contained in:
John-David Dalton
2012-04-30 22:51:14 -04:00
parent 2847b1f08e
commit e871ffeff0

View File

@@ -988,17 +988,19 @@
*/
function flatten(array, shallow) {
if (shallow) {
return concat.apply([], array);
return concat.apply(ArrayProto, array);
}
var index = -1,
var value,
index = -1,
length = array.length,
result = [];
while (++index < length) {
if (isArray(array[index])) {
push.apply(result, flatten(array[index]));
value = array[index];
if (isArray(value)) {
push.apply(result, flatten(value));
} else {
result.push(array[index]);
result.push(value);
}
}
return result;