mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 04:17:49 +00:00
Simplify _.flatten and add benchmarks.
Former-commit-id: f541328bf680a75abea68bce813820def375f4a0
This commit is contained in:
@@ -976,9 +976,6 @@
|
||||
* // => [1, 2, 3, [[4]]];
|
||||
*/
|
||||
function flatten(array, shallow) {
|
||||
if (shallow) {
|
||||
return concat.apply(ArrayProto, array);
|
||||
}
|
||||
var value,
|
||||
index = -1,
|
||||
length = array.length,
|
||||
@@ -987,7 +984,7 @@
|
||||
while (++index < length) {
|
||||
value = array[index];
|
||||
if (isArray(value)) {
|
||||
push.apply(result, flatten(value));
|
||||
push.apply(result, shallow ? value : flatten(value));
|
||||
} else {
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user