mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Optimized compact method by using a counter in place of Array.prototype.push()
This commit is contained in:
committed by
John-David Dalton
parent
3633d3cd73
commit
9a1de81fc5
@@ -4501,12 +4501,13 @@
|
|||||||
function compact(array) {
|
function compact(array) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = array ? array.length : 0,
|
length = array ? array.length : 0,
|
||||||
result = [];
|
result = [],
|
||||||
|
cur = 0,
|
||||||
|
value;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var value = array[index];
|
if (value = array[index]) {
|
||||||
if (value) {
|
result[cur++] = value;
|
||||||
result.push(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user