mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
lodash: Cleanup flatten avoiding the use of an extraneous empty array. [jddalton]
Former-commit-id: 6a1eebceb77dd59d34659a295c4a7a2dce92e8a9
This commit is contained in:
12
lodash.js
12
lodash.js
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user