mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47: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) {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user