Optimized compact method by using a counter in place of Array.prototype.push()

This commit is contained in:
robertmesserle
2013-12-06 09:32:25 -08:00
committed by John-David Dalton
parent 3633d3cd73
commit 9a1de81fc5

View File

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