mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +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) {
|
function flatten(array, shallow) {
|
||||||
if (shallow) {
|
if (shallow) {
|
||||||
return concat.apply([], array);
|
return concat.apply(ArrayProto, array);
|
||||||
}
|
}
|
||||||
var index = -1,
|
var value,
|
||||||
|
index = -1,
|
||||||
length = array.length,
|
length = array.length,
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
if (isArray(array[index])) {
|
value = array[index];
|
||||||
push.apply(result, flatten(array[index]));
|
if (isArray(value)) {
|
||||||
|
push.apply(result, flatten(value));
|
||||||
} else {
|
} else {
|
||||||
result.push(array[index]);
|
result.push(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user