From 9a1de81fc53b9ce993a775a5f1516861b4d95ad5 Mon Sep 17 00:00:00 2001 From: robertmesserle Date: Fri, 6 Dec 2013 09:32:25 -0800 Subject: [PATCH] Optimized compact method by using a counter in place of Array.prototype.push() --- lodash.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index fcb2fa4e1..fbb814194 100644 --- a/lodash.js +++ b/lodash.js @@ -4501,12 +4501,13 @@ function compact(array) { var index = -1, length = array ? array.length : 0, - result = []; + result = [], + cur = 0, + value; while (++index < length) { - var value = array[index]; - if (value) { - result.push(value); + if (value = array[index]) { + result[cur++] = value; } } return result;