From e871ffeff0b11838756d333d5ec754b0433671ca Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 30 Apr 2012 22:51:14 -0400 Subject: [PATCH] lodash: Cleanup `flatten` avoiding the use of an extraneous empty array. [jddalton] Former-commit-id: 6a1eebceb77dd59d34659a295c4a7a2dce92e8a9 --- lodash.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lodash.js b/lodash.js index 97769b28e..8b37deace 100644 --- a/lodash.js +++ b/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;