From 5315058e2d9094276738076b61a193e21eba54f5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 23 May 2012 02:19:35 -0400 Subject: [PATCH] Simplify `_.flatten` and add benchmarks. Former-commit-id: f541328bf680a75abea68bce813820def375f4a0 --- lodash.js | 5 +---- perf/index.html | 4 ++-- perf/perf.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/lodash.js b/lodash.js index ffe815dd7..bdfdc6039 100644 --- a/lodash.js +++ b/lodash.js @@ -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); } diff --git a/perf/index.html b/perf/index.html index bb731ce44..52adf326c 100644 --- a/perf/index.html +++ b/perf/index.html @@ -12,11 +12,11 @@ - + - +