Simplify _.flatten and add benchmarks.

Former-commit-id: f541328bf680a75abea68bce813820def375f4a0
This commit is contained in:
John-David Dalton
2012-05-23 02:19:35 -04:00
parent 26d9cc972e
commit 5315058e2d
3 changed files with 53 additions and 9 deletions

View File

@@ -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);
}